Tutorial · JavaScript, Python, PHP

Validate VAT numbers in code

Three levels of VAT number validation, from a quick regex to a live registration check, with code you can copy.

Updated October 1, 2026 · 2 min read

1. Normalize and check the format

Customers type VAT numbers with spaces, dots and dashes. Normalize first, then match the country’s pattern (all formats):

const FORMATS = {
  DE: /^DE\d{9}$/,
  FR: /^FR[0-9A-HJ-NP-Z]{2}\d{9}$/,
  NL: /^NL\d{9}B\d{2}$/,
  // … one entry per country
};

function looksValid(input) {
  const vat = input.toUpperCase().replace(/[\s.\-]/g, "");
  const pattern = FORMATS[vat.slice(0, 2)];
  return Boolean(pattern && pattern.test(vat));
}

2. Check digits (Python)

python-stdnum implements the official check-digit algorithms of every EU country:

from stdnum.eu import vat

vat.is_valid("DE 136 695 976")   # True
vat.compact("DE 136 695 976")    # 'DE136695976'

3. Check the registration with an API

JavaScript (Node.js)

const res = await fetch(
  `https://api.vatcheckapi.com/v2/check?vat_number=${encodeURIComponent(vat)}`,
  { headers: { apikey: process.env.VATCHECKAPI_KEY } },
);
const result = await res.json();
if (result.registration_info?.is_registered) {
  // valid: apply the reverse charge, store result.registration_info.checked_at
}

Python

import os, requests

r = requests.get(
    "https://api.vatcheckapi.com/v2/check",
    params={"vat_number": "LU26375245"},
    headers={"apikey": os.environ["VATCHECKAPI_KEY"]},
    timeout=30,
)
info = r.json().get("registration_info", {})
print(info.get("is_registered"), info.get("name"))

PHP

$ch = curl_init('https://api.vatcheckapi.com/v2/check?vat_number=' . urlencode($vat));
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['apikey: ' . getenv('VATCHECKAPI_KEY')],
    CURLOPT_TIMEOUT => 30,
]);
$result = json_decode(curl_exec($ch), true);
$registered = $result['registration_info']['is_registered'] ?? false;

Handle errors

Frequently asked questions

Is a regex enough to validate a VAT number?

No. A regex catches wrong formats, and check-digit algorithms catch most typos, but only VIES or HMRC can tell you whether the number is actually registered.

Should I validate VAT numbers in the browser?

Do the format check in the browser for instant feedback, and the registration check on your server, so your API key stays secret.

VAT validation API

Validate VAT numbers in your app

vatcheckapi checks the format and checksum of EU and UK VAT numbers and confirms the registration with VIES and HMRC, with company name and address where the country provides them.

/v2/check documentation VAT number API All documentation

150 free validations every month. No credit card required.

GET https://api.vatcheckapi.com/v2/check?vat_number=LU26375245

{
  "country_code": "LU",
  "vat_number": "26375245",
  "format_valid": true,
  "checksum_valid": true,
  "registration_info": {
    "is_registered": true,
    "name": "AMAZON EUROPE CORE S.A R.L.",
    "address": "38, AVENUE JOHN F. KENNEDY\nL-1855  LUXEMBOURG",
    "checked_at": "2023-01-11T12:30:28.000000Z"
  }
}

Keep reading

Start using our VAT Validation API for free today!

Get 150 validations / month for free