Regex to Match an IBAN
Copy the pattern, paste bank account numbers, and see which fit the IBAN shape. Below: structure and why regex can't verify the checksum.
What this pattern matches
It matches the general IBAN shape: a country code, two check digits, and a country-specific account block.
Part by part
[A-Z]{2} — the ISO country code (e.g. DE, GB).
\d{2} — two check digits.
[A-Z0-9]{11,30} — the BBAN, 11 to 30 alphanumerics depending on country.
Format vs validity
IBAN length is fixed per country and the check digits follow a mod-97 rule. Regex checks the shape only; a real validator recomputes mod-97 and enforces the exact per-country length.
Use it in your code
import re
text = "DE89370400440532013000, GB29NWBK60161331926819, FR1420041010050500013M02606, INVALID12"
pattern = r'''[A-Z]{2}\d{2}[A-Z0-9]{11,30}'''
for m in re.finditer(pattern, text):
print(m.group())
const text = "DE89370400440532013000, GB29NWBK60161331926819, FR1420041010050500013M02606, INVALID12";
const re = new RegExp(String.raw`[A-Z]{2}\d{2}[A-Z0-9]{11,30}`, "g");
console.log(text.match(re));
FAQ
Why the 11 to 30 range?
IBAN total length varies by country (e.g. Norway 15, Malta 31). The range covers the account portion after the 4-char prefix.
Should IBANs have spaces?
Printed IBANs are grouped in fours for readability, but the canonical form has no spaces. Strip spaces before matching.
Can regex confirm an IBAN is valid?
No. It checks the format only. Validity needs the mod-97 checksum, which is arithmetic, not pattern matching.