Pattern: International bank account number

“International bank account number” is one of the patterns that you can select on the Match panel. Use this pattern to match an international bank account number from any of the countries that have adopted the IBAN standard.

This example shows how you can use the “international bank account number” pattern to perform basic validation to check whether a string (from user input) has the format of a valid IBAN. You can find this example as “Pattern: international bank account number” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample that has a block of valid card numbers and a block of invalid card numbers for each of the major international bank account brands:
    AD12 0001 2030 2003 5910 0100
    AE07 0331 2345 6789 0123 456
    AL47 2121 1009 0000 0002 3569 8741
    AT61 1904 3002 3457 3201
    AZ21 NABZ 0000 0000 1370 1000 1944
    BA39 1290 0794 0102 8494
    BE68 5390 0754 7034
    BG80 BNBG 9661 1020 3456 78
    BH67 BMAG 0000 1299 1234 56
    BI42 10000 10001 00003320451 81
    BR18 0036 0305 0000 1000 9795 493C 1
    BY13 NBRB 3600 9000 0000 2Z00 AB00
    CH93 0076 2011 6238 5295 7
    CR05 0152 0200 1026 2840 66
    CY17 0020 0128 0000 0012 0052 7600
    CZ65 0800 0000 1920 0014 5399
    DE89 3704 0044 0532 0130 00
    DJ21 0001 0000 0001 5400 0100 186
    DK50 0040 0440 1162 43
    DO28 BAGR 0000 0001 2124 5361 1324
    EE38 2200 2210 2014 5685
    EG38 0019 0005 0000 0000 2631 8000 2
    ES91 2100 0418 4502 0005 1332
    FI21 1234 5600 0007 85
    FK88 SC12 3456 7890 12
    FO62 6460 0001 6316 34
    FR14 2004 1010 0505 0001 3M02 606
    GB29 NWBK 6016 1331 9268 19
    GE29 NB00 0000 0101 9049 17
    GI75 NWBK 0000 0000 7099 453
    GL89 6471 0001 0002 06
    GR16 0110 1250 0000 0001 2300 695
    GT82 TRAJ 0102 0000 0012 1002 9690
    HN88 CABF 0000 0000 0002 5000 5469
    HR12 1001 0051 8630 0016 0
    HU42 1177 3016 1111 1018 0000 0000
    IE29 AIBK 9311 5212 3456 78
    IL62 0108 0000 0009 9999 999
    IQ98 NBIQ 8501 2345 6789 012
    IS14 0159 2600 7654 5510 7303 39
    IT60 X054 2811 1010 0000 0123 456
    JO94 CBJO 0010 0000 0000 0131 0003 02
    KW81 CBKU 0000 0000 0000 1234 5601 01
    KZ86 125K ZT50 0410 0100
    LB62 0999 0000 0001 0019 0122 9114
    LC55 HEMM 0001 0001 0012 0012 0002 3015
    LI21 0881 0000 2324 013A A
    LT12 1000 0111 0100 1000
    LU28 0019 4006 4475 0000
    LV80 BANK 0000 4351 9500 1
    LY83 002 048 000020100120361
    MC58 1122 2000 0101 2345 6789 030
    MD24 AG00 0225 1000 1310 4168
    ME25 5050 0001 2345 6789 51
    MK07 2501 2000 0058 984
    MN12 1234 1234 5678 9123
    MR13 0002 0001 0100 0012 3456 753
    MT84 MALT 0110 0001 2345 MTLC AST0 01S
    MU17 BOMM 0101 1010 3030 0200 000M UR
    NI45 BAPR 0000 0013 0000 0355 8124
    NL91 ABNA 0417 1643 00
    NO93 8601 1117 947
    OM81 0180 0000 0129 9123 456
    PK36 SCBL 0000 0011 2345 6702
    PL61 1090 1014 0000 0712 1981 2874
    PS92 PALS 0000 0000 0400 1234 5670 2
    PT50 0002 0123 1234 5678 9015 4
    QA58 DOHB 0000 1234 5678 90AB CDEF G
    RO49 AAAA 1B31 0075 9384 0000
    RS35 2600 0560 1001 6113 79
    RU03 0445 2522 5408 1781 0538 0913 1041 9
    SA03 8000 0000 6080 1016 7519
    SC18 SSCB 1101 0000 0000 0000 1497 USD
    SD21 2901 0501 2340 01
    SE45 5000 0000 0583 9825 7466
    SI56 2633 0001 2039 086
    SK31 1200 0000 1987 4263 7541
    SM86 U032 2509 8000 0000 0270 100
    SO21 1000 0010 0100 0100 141
    ST23 0001 0001 0051 8453 1014 6
    SV 62 CENR 00000000000000700025
    TL38 0080 0123 4567 8910 157
    TN59 1000 6035 1835 9847 8831
    TR33 0006 1005 1978 6457 8413 26
    UA21 3223 1300 0002 6007 2335 6600 1
    VA59 001 1230 0001 2345 678
    VG96 VPVG 0000 0123 4567 8901
    XK05 1212 0123 4567 8906
    YE15 CBYE 0001 0188 6123 4567 8912 34
  3. Set the subject scope to “line by line” to treat each line in the sample as a separate input string.
  4. On the Match panel, set “begin regex match at” to “start of text”, and set “end regex match at” to “end of text” to make sure the regex validates the input in its entirety.
  5. Click the Add First Field button to add field 1.
  6. In the “pattern to match field” drop-down list, select “international bank account number”.



  7. Right-click the list of countries and click the Check SEPA menu item. This checks all the countries that are part of the Single European Payments Area.
  8. Click “spaces anywhere” to allow the IBAN to be spaced irregularly. In an actual application, it would be more efficient to generate the regex with the “no spaces” option and remove spaces from the user’s input before validating it with the regular expression.
  9. Set the “field validation mode” to “average”.
  10. On the Regex panel, select “Python 3.13” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \A(?:AD(?: ?[0-9]){10}(?: ?[0-9A-Z]){12}|(?:AT|EE|LT)(?: ?[0-9]){18}|BE(?: ?[0-9]){14}|BG(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9]){6}(?: ?[0-9A-Z]){8}|(?:CH|LI)(?: ?[0-9]){7}(?: ?[0-9A-Z]){12}|CY(?: ?[0-9]){10}(?: ?[0-9A-Z]){16}|(?:CZ|ES|SE|SK)(?: ?[0-9]){22}|(?:DE|VA)(?: ?[0-9]){20}|(?:DK|FI)(?: ?[0-9]){16}|(?:FR|MC)(?: ?[0-9]){12}(?: ?[0-9A-Z]){11}(?: ?[0-9]){2}|(?:GB|IE)(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9]){14}|GI(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9A-Z]){15}|GR(?: ?[0-9]){9}(?: ?[0-9A-Z]){16}|HR(?: ?[0-9]){19}|(?:HU|PL)(?: ?[0-9]){26}|IS(?: ?[0-9]){24}|(?:IT|SM)(?: ?[0-9]){2} ?[A-Z](?: ?[0-9]){10}(?: ?[0-9A-Z]){12}|LU(?: ?[0-9]){5}(?: ?[0-9A-Z]){13}|LV(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9A-Z]){13}|MT(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9]){5}(?: ?[0-9A-Z]){18}|NL(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9]){10}|NO(?: ?[0-9]){13}|PT(?: ?[0-9]){23}|RO(?: ?[0-9]){2}(?: ?[A-Z]){4}(?: ?[0-9A-Z]){16}|SI(?: ?[0-9]){17})\Z
    Required options: Case insensitive; Exact spacing.
    Unused options: Dot doesn’t match line breaks; ^$ don’t match at line breaks.
  11. The Samples panel now highlights the valid international bank account numbers matched by our regular expression:
    AD12 0001 2030 2003 5910 0100
    AE07 0331 2345 6789 0123 456
    AL47 2121 1009 0000 0002 3569 8741
    AT61 1904 3002 3457 3201
    AZ21 NABZ 0000 0000 1370 1000 1944
    BA39 1290 0794 0102 8494
    BE68 5390 0754 7034
    BG80 BNBG 9661 1020 3456 78
    BH67 BMAG 0000 1299 1234 56
    BI42 10000 10001 00003320451 81
    BR18 0036 0305 0000 1000 9795 493C 1
    BY13 NBRB 3600 9000 0000 2Z00 AB00
    CH93 0076 2011 6238 5295 7
    CR05 0152 0200 1026 2840 66
    CY17 0020 0128 0000 0012 0052 7600
    CZ65 0800 0000 1920 0014 5399
    DE89 3704 0044 0532 0130 00
    DJ21 0001 0000 0001 5400 0100 186
    DK50 0040 0440 1162 43
    DO28 BAGR 0000 0001 2124 5361 1324
    EE38 2200 2210 2014 5685
    EG38 0019 0005 0000 0000 2631 8000 2
    ES91 2100 0418 4502 0005 1332
    FI21 1234 5600 0007 85
    FK88 SC12 3456 7890 12
    FO62 6460 0001 6316 34
    FR14 2004 1010 0505 0001 3M02 606
    GB29 NWBK 6016 1331 9268 19
    GE29 NB00 0000 0101 9049 17
    GI75 NWBK 0000 0000 7099 453
    GL89 6471 0001 0002 06
    GR16 0110 1250 0000 0001 2300 695
    GT82 TRAJ 0102 0000 0012 1002 9690
    HN88 CABF 0000 0000 0002 5000 5469
    HR12 1001 0051 8630 0016 0
    HU42 1177 3016 1111 1018 0000 0000
    IE29 AIBK 9311 5212 3456 78
    IL62 0108 0000 0009 9999 999
    IQ98 NBIQ 8501 2345 6789 012
    IS14 0159 2600 7654 5510 7303 39
    IT60 X054 2811 1010 0000 0123 456
    JO94 CBJO 0010 0000 0000 0131 0003 02
    KW81 CBKU 0000 0000 0000 1234 5601 01
    KZ86 125K ZT50 0410 0100
    LB62 0999 0000 0001 0019 0122 9114
    LC55 HEMM 0001 0001 0012 0012 0002 3015
    LI21 0881 0000 2324 013A A
    LT12 1000 0111 0100 1000
    LU28 0019 4006 4475 0000
    LV80 BANK 0000 4351 9500 1
    LY83 002 048 000020100120361
    MC58 1122 2000 0101 2345 6789 030
    MD24 AG00 0225 1000 1310 4168
    ME25 5050 0001 2345 6789 51
    MK07 2501 2000 0058 984
    MN12 1234 1234 5678 9123
    MR13 0002 0001 0100 0012 3456 753
    MT84 MALT 0110 0001 2345 MTLC AST0 01S
    MU17 BOMM 0101 1010 3030 0200 000M UR
    NI45 BAPR 0000 0013 0000 0355 8124
    NL91 ABNA 0417 1643 00
    NO93 8601 1117 947
    OM81 0180 0000 0129 9123 456
    PK36 SCBL 0000 0011 2345 6702
    PL61 1090 1014 0000 0712 1981 2874
    PS92 PALS 0000 0000 0400 1234 5670 2
    PT50 0002 0123 1234 5678 9015 4
    QA58 DOHB 0000 1234 5678 90AB CDEF G
    RO49 AAAA 1B31 0075 9384 0000
    RS35 2600 0560 1001 6113 79
    RU03 0445 2522 5408 1781 0538 0913 1041 9
    SA03 8000 0000 6080 1016 7519
    SC18 SSCB 1101 0000 0000 0000 1497 USD
    SD21 2901 0501 2340 01
    SE45 5000 0000 0583 9825 7466
    SI56 2633 0001 2039 086
    SK31 1200 0000 1987 4263 7541
    SM86 U032 2509 8000 0000 0270 100
    SO21 1000 0010 0100 0100 141
    ST23 0001 0001 0051 8453 1014 6
    SV 62 CENR 00000000000000700025
    TL38 0080 0123 4567 8910 157
    TN59 1000 6035 1835 9847 8831
    TR33 0006 1005 1978 6457 8413 26
    UA21 3223 1300 0002 6007 2335 6600 1
    VA59 001 1230 0001 2345 678
    VG96 VPVG 0000 0123 4567 8901
    XK05 1212 0123 4567 8906
    YE15 CBYE 0001 0188 6123 4567 8912 34

The regular expression can only check whether the IBAN starts with the correct country code and has the correct number of digits (and possibly letters for some countries) following it. A full validation check requires both the regular expression to check the format of the IBAN and the modulo 97 test. That is a mathematical operation which regular expressions cannot do. The following Python snippet implements the modulo 97 test.

def iban_mod97(iban: str) -> bool:
    # Normalize the IBAN by removing spaces and converting to uppercase
    iban = iban.replace(' ', '').upper()
    # Move the first four characters to the end
    iban = iban[4:] + iban[:4]
    # Replace letters with their corresponding numbers
    iban_numeric = ''.join(str(int(char, 36)) for char in iban)
    # Calculate the modulo 97
    return int(iban_numeric) % 97 == 1

Reference