DEV Community

mieldekien
mieldekien

Posted on

Belgian VAT validation in 5 lines (with company name lookup)

If you've ever had to validate a Belgian VAT number in code, you know the dance:

  1. Strip whitespace and the BE prefix
  2. Run a modulo-97 checksum (because Belgium is fancy)
  3. Hit the VIES SOAP endpoint to confirm it actually exists
  4. Parse the XML response to get the company name (if VIES feels like sharing it that day)

That's 80 lines of code, an XML parser, and a pile of error handling. For something that should be a one-liner.

I got tired of writing it. So I built a small API that does all of it in a single GET request.

The 5-line version


js
const res = await fetch(
  "https://belgian-vat-validator.p.rapidapi.com/api/validate?number=BE0417497106",
  { headers: { "X-RapidAPI-Key": "YOUR_KEY",
               "X-RapidAPI-Host": "belgian-vat-validator.p.rapidapi.com" } }
);
const data = await res.json();
console.log(data.valid, data.vies.name);
// → true "NV Anheuser-Busch InBev"

That's it. Format check, modulo-97 checksum, VIES lookup, and company name — all in under 200ms.

What you get back

{
  "input": "BE0417497106",
  "number": "BE0417497106",
  "formatted": "BE 0417 497 106",
  "valid": true,
  "checks": {
    "format": true,
    "checksum": true,
    "vies": true
  },
  "vies": {
    "available": true,
    "isValid": true,
    "name": "NV Anheuser-Busch InBev",
    "address": "Brouwerijplein 1\n3000 Leuven"
  }
}

Two things I want to point out:

- checks is a per-stage breakdown. If a number fails, you can tell whether it's a typo, a checksum error, or whether VIES says it doesn't exist. Useful for showing users what went wrong.
- vies.name and vies.address are free. A lot of devs assume VIES blocks company info. It do is there and it's official.

Why not just call VIES directly?

You can. The catch:

1. VIES is SOAP. You'll need an XML library or fast-xml-parser and a wrapper.
2. VIES is unreliable. It goes down for hours at a time, especially around month-end when accountants hammer it.
3. VIES gives no format/checksum errors. A malformed number returns the same "invalid" as aou'll still need your own pre-validation.
4. You're hand-rolling the modulo-97. It's not hard, but it's easy to get wrong silently (off-by-one in the slicing, integer overflow on 8-digit prefix).

Wrap all that and you've written half a library before you've shipped anything.

When to use this (and when not to)

Use it if you're building:
- Invoice or quote generation that needs to validate customer VAT before saving
- B2B onboarding flows where typos cause downstream pain
- Internal tooling for sales / finance / accounting
- An MVP where "build it yourself later" is the right tradeoff

Don't use it if:
- You process >100k VAT lookups per day — at that volume, run your own VIES proxy.
- You need EU-wide coverage today (it's BE-only; NL/FR/DE are on the list).
- Your customers won't tolerate any external dependency for VAT checks (regulated industrie

Try it

There's a free tier (https://rapidapi.com/mieldekien8660/api/belgian-vat-validator) with 10 wire up an MVP without a credit card.

If you have feedback or want a country added, I read every message.

Built by miel1 (https://rapidapi.com/mieldekien8660) on RapidAPI (https://rapidapi.com).[]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)