Advertisement

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.

The pattern
^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
GB82WEST12345698765432MatchUK IBAN, 22 charactersTry →
DE89370400440532013000MatchGerman IBANTry →
NL91ABNA0417164300MatchDutch IBAN, 18 charactersTry →
de89370400440532013000No matchlowercase — uppercase before testingTry →
GB82 WEST 1234 5698 7654 32No matchspaces stripped before matching (see notes)Try →
GB8No matchmissing check digitsTry →

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

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

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.

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.