Regex for EU VAT number
EU VAT registration — 2-letter country + 8–12 alphanumerics.
The EU VAT number regex is ^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$ — copy it below, or open it in the explainer for a token-by-token breakdown.
The pattern
^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$
What it matches
DE123456789FRAB123456789GB123456789
What it doesn't match
DE12345XX123456789US123456789
Notes & gotchas
Each member state has its own VAT format, but they all start with the 2-letter country code. The total length varies (DE=11 chars, FR=13, IT=13). Lengths shown are loose; validate with VIES for the strict format.
Code in your language
Use the explainer's Code tab to generate ready-to-paste snippets in JavaScript, Python, Java, .NET, Go, Ruby, and PHP for this pattern.
Open in explainer →Token-by-token breakdown
Every part of the pattern, left to right:
| Token | Meaning |
|---|---|
^ | start of string (or line in multiline mode) |
( | start of a capturing group |
AT | literal text “AT” |
| | OR — try the alternative |
BE | literal text “BE” |
| | OR — try the alternative |
BG | literal text “BG” |
| | OR — try the alternative |
CY | literal text “CY” |
| | OR — try the alternative |
CZ | literal text “CZ” |
| | OR — try the alternative |
DE | literal text “DE” |
| | OR — try the alternative |
DK | literal text “DK” |
| | OR — try the alternative |
EE | literal text “EE” |
| | OR — try the alternative |
EL | literal text “EL” |
| | OR — try the alternative |
ES | literal text “ES” |
| | OR — try the alternative |
FI | literal text “FI” |
| | OR — try the alternative |
FR | literal text “FR” |
| | OR — try the alternative |
GB | literal text “GB” |
| | OR — try the alternative |
HR | literal text “HR” |
| | OR — try the alternative |
HU | literal text “HU” |
| | OR — try the alternative |
IE | literal text “IE” |
| | OR — try the alternative |
IT | literal text “IT” |
| | OR — try the alternative |
LT | literal text “LT” |
| | OR — try the alternative |
LU | literal text “LU” |
| | OR — try the alternative |
LV | literal text “LV” |
| | OR — try the alternative |
MT | literal text “MT” |
| | OR — try the alternative |
NL | literal text “NL” |
| | OR — try the alternative |
PL | literal text “PL” |
| | OR — try the alternative |
PT | literal text “PT” |
| | OR — try the alternative |
RO | literal text “RO” |
| | OR — try the alternative |
SE | literal text “SE” |
| | OR — try the alternative |
SI | literal text “SI” |
| | OR — try the alternative |
SK | literal text “SK” |
) | end of group |
[A-Z0-9]{8,12} | between 8 and 12 times: any of: uppercase letters, digits |
$ | end of string (or line in multiline mode) |
About this pattern
European Union identifiers follow standards set by individual member states with EU-wide coordination (VAT VIES, IBAN/SEPA, etc.). The regex validates structure; for production use, validate via the appropriate registry.
Quick usage in different languages
This exact pattern — with the correct escaping and idioms for each language:
- JavaScript:
/^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$/.test(value) - Python:
re.match(r"^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$", value) - Java:
Pattern.compile("^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$").matcher(value).matches() - C# / .NET:
Regex.IsMatch(value, @"^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$") - Go:
regexp.MustCompile(`^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$`).MatchString(value) - Ruby:
/^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$/.match?(value) - PHP:
preg_match('~^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|GB|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[A-Z0-9]{8,12}$~', $value)
The explainer’s Code tab regenerates these for any pattern you paste, and the downloadable cheat sheet bundles the breakdown, all seven snippets, and the pitfalls below onto one printable page.
Common pitfalls
- Anchored to the whole string. This pattern uses ^ and $, so it requires the entire input to match. To find it inside a longer text, drop the anchors and use the global (g) flag.
- Uppercase only. Ranges like [A-Z] won't match lowercase. Add a-z (or the i flag) if lowercase input should be accepted.
- Validate beyond format. Matching the format doesn't guarantee the value is real. Confirm the eu vat number against a source of truth (database, API, or checksum) where it matters.
Standards & sources
This pattern is based on the following authoritative specification(s) and issuing authorities. Formats can change — always confirm against the primary source.
Related patterns
More patterns in the Europe 🇪🇺 category:
See also
Browse all 300 patterns in the library, or open this regex in the interactive explainer for a token-by-token breakdown, live testing, and code in seven languages.
Want more patterns? Browse the full library →