There is a regular expression for confirming the VAT number of 27 EU countries, presented in the Book of Regular Expressions, 2nd edition, 4.21. Section of European VAT numbers .
With this regular expression there is no calculation check, but it will still be able to check single lines, which are likely to be EU VAT numbers.
Before checking, the characters [-.●] or [^A-Z0-9] must be deleted. Then use
(?xi)^( (AT)?U[0-9]{8} | # Austria (BE)?0[0-9]{9} | # Belgium (BG)?[0-9]{9,10} | # Bulgaria (HR)?[0-9]{11} | # Croatia (CY)?[0-9]{8}[AZ] | # Cyprus (CZ)?[0-9]{8,10} | # Czech Republic (DE)?[0-9]{9} | # Germany (DK)?[0-9]{8} | # Denmark (EE)?[0-9]{9} | # Estonia (EL)?[0-9]{9} | # Greece ES[AZ][0-9]{7}(?:[0-9]|[AZ]) | # Spain (FI)?[0-9]{8} | # Finland (FR)?[0-9A-Z]{2}[0-9]{9} | # France (GB)?([0-9]{9}([0-9]{3})?|[AZ]{2}[0-9]{3}) | # United Kingdom (HU)?[0-9]{8} | # Hungary (IE)?[0-9]{7}[AZ]{1,2} | # Ireland (IE)?[0-9][AZ][0-9]{5}[AZ] | # Ireland (2) (IT)?[0-9]{11} | # Italy (LT)?([0-9]{9}|[0-9]{12}) | # Lithuania (LU)?[0-9]{8} | # Luxembourg (LV)?[0-9]{11} | # Latvia (MT)?[0-9]{8} | # Malta (NL)?[0-9]{9}B[0-9]{2} | # Netherlands (PL)?[0-9]{10} | # Poland (PT)?[0-9]{9} | # Portugal (RO)?[0-9]{2,10} | # Romania (SE)?[0-9]{12} | # Sweden (SI)?[0-9]{8} | # Slovenia (SK)?[0-9]{10} # Slovakia )$
View regex demo
I have added the Croatian VAT alternative here.
Please note that if you expect country codes, delete ? quantifiers after closing parentheses.
When new countries join the European Union or member states change their rules for VAT numbers, regular expression needs to be updated.
Please note that the regular expression in the cookbook does not meet the definition of the Wiki-Irish VAT number.
In addition, it is impossible to fully verify this using a regular expression, because some VAT numbers require specific data that is either difficult to obtain or should be calculated using a common programming language:
- The French first 2 digits are the “key”, and the French key is calculated as follows:
Key = [ 12 + 3 * ( SIREN modulo 97 ) ] modulo 97 , for example: Key = [ 12 + 3 * ( 404,833,048 modulo 97 ) ] modulo 97 = [12 + 3*56] modulo 97 = 180 modulo 97 = 83 therefore the tax number for 404,833,048 is Key = [ 12 + 3 * ( 404,833,048 modulo 97 ) ] modulo 97 = [12 + 3*56] modulo 97 = 180 modulo 97 = 83 404,833,048 FR 83,404,833,048 Source: www.insee.fr. - Finland's final VAT figure is a check digit using MOD 11-2
- Italian VAT has a provincial code with 3 characters (indices 8, 9, 10)
- Slovak VAT number should be divided by 11
source share