Identity
EU VAT Number Regex
A European Union VAT identification number starts with a two-letter member state prefix and is followed by a national block of digits and sometimes letters. Greece uses EL rather than its ISO code GR, and the pattern reflects that. This is a practical check for B2B checkout pages, invoicing tools and supplier onboarding forms that need to reject obvious mistakes before calling an official lookup service. The limit is that national formats differ widely in length and structure, so this broad rule accepts some impossible combinations and never confirms registration status.
Pattern (JavaScript)
/^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$/Starts at the start of the line/string, then (the text "AT" OR the text "BE" OR the text "BG" OR the text "CY" OR the text "CZ" OR the text "DE" OR the text "DK" OR the text "EE" OR the text "EL" OR the text "ES" OR the text "FI" OR the text "FR" OR the text "HR" OR the text "HU" OR the text "IE" OR the text "IT" OR the text "LT" OR the text "LU" OR the text "LV" OR the text "MT" OR the text "NL" OR the text "PL" OR the text "PT" OR the text "RO" OR the text "SE" OR the text "SI" OR the text "SK"), then one of the characters 0-9A-Z, between 8 and 12 times, then the end of the line/string.
Limit: Checks the shape only; it cannot tell whether a document is real or valid.
Examples
Matches
- ✓ DE123456789
- ✓ FR12345678901
- ✓ NL123456789B01
Does not match
- ✗ US123456789
- ✗ DE1234
- ✗ de123456789
Try it
0 matches (JavaScript engine)
DE123456789
FR12345678901
NL123456789B01
US123456789
DE1234
de123456789Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$/g;
const text = "DE123456789";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$')
text = 'DE123456789'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$/';
$text = 'DE123456789';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$");
String text = "DE123456789";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$`)
text := "DE123456789"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$");
var text = "DE123456789";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$").unwrap();
let text = "DE123456789";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$/
text = 'DE123456789'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why is Greece listed as EL instead of GR?
- The EU VAT system uses EL for Greece, following the Greek name of the country. Numbers starting with GR are therefore not standard EU VAT identifiers.
- Does this include Northern Ireland numbers?
- Northern Ireland traders use the XI prefix for some EU VAT purposes. Add XI to the alternation if your business needs to accept those numbers.
- How do I confirm that a VAT number is registered?
- Use the European Commission's VIES service or the relevant national tax authority. The regex only decides whether the string looks like a VAT number.