ISO 4217 Currency Code Regex
Validates that a string has the shape of an ISO 4217 currency code: exactly three uppercase letters, such as USD, EUR, or INR.
Regex Pattern
^[A-Z]{3}$Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the start of the string |
| [A-Z] | Matches a single uppercase letter A through Z |
| {3} | Repeats the uppercase letter match exactly three times |
| $ | Anchors the match to the end of the string |
Detailed Explanation
What it does
This pattern checks that an input string consists of exactly three uppercase ASCII letters, matching the structural format of ISO 4217 currency codes like USD, EUR, GBP, and JPY. It validates shape only, not membership in the official currency list.
Why it works
The character class [A-Z] restricts matches to uppercase Latin letters, and the fixed quantifier {3} combined with the start and end anchors forces the entire string to be exactly three characters, matching the fixed-width design of ISO 4217 codes, which are conventionally derived from the country code plus a currency initial.
Common use cases
- Validating a currency selector field in a checkout or billing form
- Sanity-checking a currency code parameter before calling an exchange-rate API
- Filtering transaction records for well-formed currency code fields
- Guarding against malformed currency data in imported CSV or JSON files
Edge cases
- Lowercase input like usd is rejected since the pattern is case-sensitive and requires uppercase letters
- Two-letter or four-letter strings are rejected because the length is fixed at exactly three characters
- Numeric ISO 4217 codes, like 840 for USD, are rejected since the character class only allows letters
- The pattern accepts any three-letter combination shape-wise, including retired or unassigned codes, since it performs no lookup against the real ISO 4217 list
Limitations
- Does not validate against the actual set of currently assigned ISO 4217 codes, only the three-uppercase-letter shape
- Does not distinguish active currencies from historical ones like DEM or FRF
- Case must be normalized to uppercase by the caller before validation, since the pattern is case-sensitive by default
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const currencyCodeRegex = /^[A-Z]{3}$/;
console.log(currencyCodeRegex.test('USD')); // trueCommon Mistakes
Confusing ISO 4217 currency codes with ISO 3166-1 country codes and using a two-letter pattern instead of three
Fix: Use {3} since every ISO 4217 alphabetic currency code is exactly three letters, unlike two-letter country codes
Skipping validation against a real currency list and assuming any three-letter match is a supported currency
Fix: Pair the shape check with a lookup table of currencies your system actually supports before using the code in financial logic
Allowing lowercase input to pass by adding the case-insensitive flag, hiding normalization bugs elsewhere in the pipeline
Fix: Keep the pattern case-sensitive and explicitly uppercase user input before validating
Performance Notes
- The pattern is fixed-length and anchored, making evaluation effectively constant time
- No alternation or nested quantifiers are present, so there is no backtracking risk
- For extremely high-throughput validation, a direct length and character-range check can be marginally faster than regex, though the difference is negligible in most applications
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |