Pattern: VAT number

“VAT number” is one of the patterns that you can select on the Match panel. Use it to make a field match a value added tax number from one or more European countries.

This example shows how you can use the “VAT number” pattern to check for VAT numbers from the Benelux countries. You can find this example as “Pattern: VAT 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 and a block of invalid VAT numbers:
    ATU12345678
    BE123456789
    BE0123456789
    BG123456789
    BG0123456789
    CY12345678L
    CZ12345678
    CZ123456789
    CZ1234567890
    DE123456789
    DK12345678
    EE123456789
    GR123456789
    EL123456789
    ES012345678
    ESX1234567Y
    FI12345678
    FR12123456789
    FRAB123456789
    GB123456789123
    GB123456789AB1
    HU12345678
    IE1S12345L
    IT12345678901
    LU12345678
    LT123456789
    LT123456789012
    LV12345678901
    MT12345678
    NL123456789B01
    PL1234567890
    PT123456789
    RO12345678
    RO123456789
    RO1234567890
    SE123456789012
    SI12345678
    SK1234567890
    
  3. On the Match panel, click the Add First Field button to add field 1.
  4. In the “pattern to match field” drop-down list, select “VAT number”.



  5. In the list of countries, tick Belgium, The Netherlands, and Luxembourg.
  6. In the “country code” drop-down list, select “require country code”.
  7. In the “grouping characters” drop-down list, select “none”.
  8. Set the “field validation mode” to “strict”.
  9. On the Regex panel, select “C# (.NET 2.0–8.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \b(?:LU[0-9]{8}|BE[0-1][0-9]{9}|NL[0-9]{9}B[0-9]{2})\b

    Required options: Case insensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

  10. The Samples panel now highlights the valid social security numbers matched by our regular expression:
    ATU12345678
    BE123456789
    BE0123456789
    BG123456789
    BG0123456789
    CY12345678L
    CZ12345678
    CZ123456789
    CZ1234567890
    DE123456789
    DK12345678
    EE123456789
    GR123456789
    EL123456789
    ES012345678
    ESX1234567Y
    FI12345678
    FR12123456789
    FRAB123456789
    GB123456789123
    GB123456789AB1
    HU12345678
    IE1S12345L
    IT12345678901
    LU12345678
    LT123456789
    LT123456789012
    LV12345678901
    MT12345678
    NL123456789B01
    PL1234567890
    PT123456789
    RO12345678
    RO123456789
    RO1234567890
    SE123456789012
    SI12345678
    SK1234567890
    

Reference