We built a free bulk checker for EU REX numbers (open source, no API key)
There is no API, so we read the public page carefully The Commission's validation page loads its result as a small HTML fragment. Each fact sits in a table row: a bold label, then a value cell. So the parser collects l
There is no API, so we read the public page carefully
The Commission's validation page loads its result as a small HTML fragment. Each fact sits in a table row: a bold label, then a value cell. So the parser collects label → value pairs and only trusts the ones it knows:
const re = /<b>\s*([^<]{2,80}?)\s*<\/b>\s*<\/td>\s*<td[^>]*>([\s\S]*?)<\/td>/gi;
for (let m; (m = re.exec(html)); ) rows.set(text(m[1]).toLowerCase(), text(m[2]));
const statusText = rows.get('status of the rex number');
Two rules kept it honest:
-
Never guess. If the page layout isn't recognised, the result is
unavailable, not "valid" and not "not found". A wrong "valid" could cost a buyer real duty. -
"Not valid" is not "valid". The status for a revoked number also contains the words "is valid" (
is not valid), so the check excludesnot validexplicitly.
Bugs real input found
-
Spaces inside one number. People copy numbers from PDF invoices as
NPREX 1244417670168 NPTEPC. Our first splitter treated spaces as separators and turned one number into three "wrong format" entries. Now lines, commas and semicolons separate numbers; spaces only do when every word is itself a complete REX number. - Whitespace in the "not found" box. The Commission's "does not exist" message sits in a box padded with hundreds of spaces. A 400-character window missed it. We now read the box's first paragraph instead, and our test fixture copies the real padding so this can't come back.
- Matching too broadly. Searching the whole page for "does not exist" would misread any notice containing that phrase. We read the status row first and look for the not-found message only in its own box.
Being a good citizen of a free government service
- Valid answers are cached for 6 hours, "not found" for only 10 minutes, so a new registration shows up quickly.
- One shared deadline per request, so ten slow lookups can't take a minute.
- A per-visitor hourly limit.
- We pass on only what a buyer needs: status, registration date, name and country. Address, e-mail and phone from the public record are deliberately dropped, and we don't store who checks what.
One caveat worth repeating
A valid REX number proves the exporter is registered. It does not prove the goods meet the rules of origin, or that the invoice wording is right. The checker says so on every result.
If you work on customs or trade tooling, the code is MIT-licensed: use it, and tell us what would make it more useful.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.