Pattern library / Validation
IBAN Regex (ISO 13616 Shape)
An IBAN is always CC KK …: two country letters, two check digits, then up to 30 alphanumeric BBAN characters — 34 total maximum. Regex nails that shape in one line; the real validity test is the mod-97 checksum, which belongs in code. The notes show both, and why you normalize (strip spaces, uppercase) before testing.
How the pattern works
^[A-Z]{2}— ISO 3166 country code, uppercase: regex proves shape; membership (is DE an actual IBAN country?) is a lookup.[0-9]{2}— check digits computed with mod-97: a wrong pair likeGB00…passes shape and fails checksum.- Normalize first:
s.replace(/\s/g, '').toUpperCase()— banks print groups of four, and none of those spaces belong in the value. - Per-country lengths are fixed (DE 22, GB 22, NL 18, FR 27): if you validate one country, add the exact length instead of {1,30}.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
GB82WEST12345698765432 | Match | UK IBAN, 22 characters | Try → |
DE89370400440532013000 | Match | German IBAN | Try → |
NL91ABNA0417164300 | Match | Dutch IBAN, 18 characters | Try → |
de89370400440532013000 | No match | lowercase — uppercase before testing | Try → |
GB82 WEST 1234 5698 7654 32 | No match | spaces stripped before matching (see notes) | Try → |
GB8 | No match | missing check digits | Try → |
Where to use it
JavaScript
const IBAN = /^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/;
const clean = iban.replace(/\s/g, '').toUpperCase();
IBAN.test(clean); // true for GB82WEST…
Python (mod-97 check)
def valid_iban(s):
s = re.sub(r'\s', '', s).upper()
rearranged = s[4:] + s[:4]
num = ''.join(str(ord(c) - 55) if c.isalpha() else c for c in rearranged)
return int(num) % 97 == 1 # ISO 13616 rule
SQL / BigQuery
SELECT REGEXP_CONTAINS(UPPER(REPLACE(iban, ' ', '')), r'^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$')
Common mistakes
- Shape-checking happily accepts
GB00…— always run mod-97 (eight lines, above) before trusting an IBAN for anything. - Lowercase fails
[A-Z]by design — normalize to uppercase instead of flipping the regex to case-insensitive; consistent storage beats convenient matching. - Country internals (German BLZ, French bank codes) live inside the BBAN — regex cannot decompose them; use a per-country IBAN spec table when you need parts.
FAQ
Is an IBAN that matches this regex valid?
Not yet — the shape is right, but the check digits must pass the mod-97-10 algorithm. Run the Python function above (or a library) after the shape test.
Why does my IBAN regex fail on codes with spaces?
Banks display IBANs in groups of four (GB82 WEST 1234…). Strip all whitespace and uppercase first, then test.
How long can an IBAN be?
Up to 34 characters total: 2 country + 2 check + up to 30 BBAN characters. The {1,30} tail enforces that ceiling.
Related patterns
Country Code Regex - ISO 3166 Alpha-2 / Alpha-3 · Credit Card Regex — Visa, Mastercard & Amex Shapes · Email Validation Regex — Practical Pattern to Test
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.