isValidFormat($value)) { $fail( sprintf( __('%s must be a valid 3-letter currency code in uppercase format (example: USD)', 'give'), '{field}' ) ); } elseif (!give(GiveCurrencies::class)->contains(new Currency($value))) { $fail( sprintf( __('%s must be a valid currency. Provided: %s', 'give'), '{field}', $value ) ); } } /** * Checks if a currency code is in the correct ISO 4217 format. * Valid format: exactly 3 uppercase alphabetic characters (not empty). * * @since 4.10.0 * * @param mixed $value The currency code to validate * @return bool True if the format is valid, false otherwise */ private function isValidFormat($value): bool { return is_string($value) && !empty($value) && strlen($value) === 3 && ctype_alpha($value) && $value === strtoupper($value); } }