IBAN (International Bank Account Number) in PY
Validate IBAN bank account identifiers: 2-letter country code, 2 check digits, 11–30 alphanumerics.
Try it in the PY tester →Pattern
regexPY
^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$Python (re) code
pyPython
import re
pattern = re.compile(r"^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$")
input_text = "GB29NWBK60161331926819"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
^[A-Z]{2} matches the ISO country prefix (e.g. DE, GB, FR). \d{2} matches the two-digit check sum. [A-Z0-9]{11,30}$ matches the remaining bank/account portion which varies by country between 11 and 30 characters. This validates structure but does NOT verify the mod-97 checksum — pair with a checksum function for full validation.
Examples
Input
GB29NWBK60161331926819Matches
GB29NWBK60161331926819
Input
DE89370400440532013000Matches
DE89370400440532013000
Input
1234567890No match
—