Validate Romanian VAT Numbers (CUI, RO Prefix) in Node.js

18 Nov 2026

Validate Romanian VAT Numbers (CUI, RO Prefix) in Node.js

A Romanian VAT number is RO followed by 2 to 10 digits, and those digits are the company’s CUI (cod unic de înregistrare) – but only when the business is registered for VAT. That condition is where most confusion starts, because a Romanian company can hold a CUI for years before it ever has a VAT number. This post covers the Node.js side: normalising the input, the format check, the CUI check digit, the VIES lookup, and what happens when the Romanian node is down and the tax authority’s own service steps in. For the general behaviour of the endpoint, see the Romania VAT API reference.

What a Romanian VAT number looks like

The Romanian VAT ID is:

  • RO – the VIES country prefix, which is also the ISO 3166-1 code
  • 2 to 10 digits – the CUI, also called the CIF (cod de identificare fiscală) in fiscal contexts

The Ministry of Finance assigns the code from data the trade register (ONRC) sends at incorporation. The length range and the ‘no leading zero, last digit is a check digit’ rule come from the open-source python-stdnum reference implementation rather than from a statute, so treat them as a well-documented convention, not an exhaustive specification.

What the number is not:

  • Not automatic. Having a CUI does not mean VAT registration. Registration is a separate act under the Romanian Fiscal Code, and the official name for the result is the cod de înregistrare în scopuri de TVA (VAT registration code). Romania also issues a special code under art. 317 for intra-EU transactions only, so the status in ANAF’s registry and the status in VIES can differ. For intra-EU transactions, VIES is the source EU rules point to when confirming a customer’s VAT number.
  • Not the trade register number. The număr de ordine în registrul comerțului looked like J40/1234/2005 (letter, county, sequence, year), and since 26 Jul 2024 a new 14-character format such as J2002000020022 is in use, with older entities converted gradually. Neither is a VAT number, and with both formats in use, don’t treat one regex as the only valid shape.
  • Not always a company code. Individuals such as sole traders (PFA) and liberal professionals are fiscally identified by their 13-digit personal numeric code (CNP), and their VAT identifier, if they have one, can be based on it. That makes it personal data, covered below.

Step 1: format validation in Node.js

Reject malformed input before any network call. The regex matches the pattern the vatnode API enforces, RO plus 2 to 10 digits:

const RO_VAT_PATTERN = /^RO\d{2,10}$/

function normaliseRomanianVatId(
  input: string,
  opts: { mode?: 'strict' | 'lenient' } = {}
): string | null {
  let cleaned = input.replace(/[\s.\-]/g, '').toUpperCase()
  // Lenient mode: prepend RO when the user typed only the CUI
  if (opts.mode === 'lenient' && /^\d{2,10}$/.test(cleaned)) {
    cleaned = `RO${cleaned}`
  }
  return RO_VAT_PATTERN.test(cleaned) ? cleaned : null
}

// Strict (default) – API consumers should send a fully-qualified ID
normaliseRomanianVatId('RO 1234 5678') // → 'RO12345678'
normaliseRomanianVatId('12345678') // → null

// Lenient – for checkout forms where customers paste only the CUI
normaliseRomanianVatId('12345678', { mode: 'lenient' }) // → 'RO12345678'

// Too long for the pattern, including a 13-digit CNP-length value
normaliseRomanianVatId('RO1234567890123') // → null

This pattern is deliberately looser than the convention above: it does not reject a leading zero and does not run the check digit. A string that matches is well-formed input, nothing more. vatnode rejects a 13-digit value after RO with INVALID_FORMAT (400): the API covers the RO + 2–10 digit form. Before writing any code, paste a real number into the VAT checker and see what VIES returns. Format vs valid covers the difference between a string that parses and a number that exists.

Step 2: the CUI check digit (a soft signal)

The last digit of a CUI is a check digit, which makes a cheap local filter for typos. The algorithm, as documented in python-stdnum:

  1. Take the number without its last digit and left-pad it with zeros to 9 digits.
  2. Multiply the digits by the weights 7, 5, 3, 2, 1, 7, 5, 3, 2 and add them up.
  3. Multiply the sum by 10 and take it modulo 11. A result of 10 becomes 0.
  4. The result must equal the last digit.
const CUI_WEIGHTS = [7, 5, 3, 2, 1, 7, 5, 3, 2]

function cuiCheckDigit(body: string): number {
  const padded = body.padStart(9, '0')
  let sum = 0
  for (let i = 0; i < 9; i++) {
    sum += Number(padded[i]) * CUI_WEIGHTS[i]
  }
  const digit = (sum * 10) % 11
  return digit === 10 ? 0 : digit
}

function hasValidCuiChecksum(cui: string): boolean {
  if (!/^[1-9]\d{1,9}$/.test(cui)) return false
  return cuiCheckDigit(cui.slice(0, -1)) === Number(cui[cui.length - 1])
}

// 12345678: body 1234567, padded 001234567
// 0*7 + 0*5 + 1*3 + 2*2 + 3*1 + 4*7 + 5*5 + 6*3 + 7*2 = 95
// 95 * 10 = 950, 950 mod 11 = 4
cuiCheckDigit('1234567') // → 4
hasValidCuiChecksum('12345678') // → false (the last digit is 8, not 4)

12345678 is a synthetic number used throughout this post, and it fails the checksum on purpose. A passing checksum only says the digits are internally consistent. It says nothing about whether the entity exists, whether it is VAT-registered, or whether VIES knows it. Treat a failed checksum as a hint to ask the customer to re-check their input, and a passed one as permission to continue to the real lookup. The vatnode API does not run this checksum itself – it validates the pattern from Step 1 and leaves the verdict to the registries.

Step 3: VIES for Romania

Format-valid input goes to VIES, which routes an RO query to the Romanian node and relays back one of:

  • A valid or invalid answer. For Romania the trader name and address are typically attached – treat them as commonly present, not guaranteed on every request.
  • MS_UNAVAILABLE or MS_MAX_CONCURRENT_REQ – the Romanian node is down or saturated.
  • SERVICE_UNAVAILABLE or GLOBAL_MAX_CONCURRENT_REQ – VIES itself is degraded or overloaded.
  • A timeout, if the node doesn’t answer in time.

When no fallback answers, the vatnode API surfaces the last three as its own VIES_UNAVAILABLE or UPSTREAM_TIMEOUT codes (see Error handling below), not VIES’s raw fault strings.

Only a VIES answer can carry a consultation number, and only when your request includes a requester VAT number and VIES issues one. The consultation number explainer covers what it is and what it is not. Every member-state node goes down sometimes, so read the VIES downtime guide before you design the unhappy path.

Step 4: the ANAF fallback

Romania is one of the countries where a national source exists: ANAF, the Romanian tax authority, publishes a public web service of VAT payers. The service accepts a POST with a list of { "cui": <number>, "data": "YYYY-MM-DD" } objects, needs no authentication, takes at most 100 CUIs per request and allows at most one request per second, per ANAF’s documentation (v9). Every query carries a date, so the question it answers is ‘was this entity a VAT payer on that date’.

vatnode calls it only when both of these hold:

  • VIES failed with a transient error (MS_UNAVAILABLE, MS_MAX_CONCURRENT_REQ, TIMEOUT, SERVICE_UNAVAILABLE or GLOBAL_MAX_CONCURRENT_REQ), and
  • your account has no requester VAT number set in dashboard Account details.

Romania is not raced: ANAF is asked only after VIES has failed, never in parallel with it. If ANAF fails too, you get the original VIES error back. When a requester VAT is set, vatnode does not downgrade to ANAF at all and returns the VIES error (for example VIES_UNAVAILABLE, 503), because only VIES issues a consultation number and a fallback answer would silently drop it.

What an ANAF_RO response means:

  • valid is ANAF’s scpTVA flag – the entity is a VAT payer on the queried date, in ANAF’s own registry.
  • companyName, companyAddress, companyRegistrationDate, companyForm and industryDescription come from ANAF’s record (any of them can be null).
  • consultationNumber is null, always. commercialName and companyStatus are null and secondaryActivities is empty.

A fallback valid is not a VIES confirmation. It is a national registry result, and it does not tell you whether reverse charge applies. A valid: false from ANAF means the entity was not found or was not a VAT payer that day. It does not prove the number is invalid in VIES, because the status in ANAF’s registry and in VIES can differ (see the art. 317 note above). That is the same trade-off the Polish MF white list fallback makes, and VIES vs national VAT databases explains why the two answers are different questions.

There are three ways to cover the Romanian fallback, fastest first:

  1. Use vatnode. It already runs VIES RO plus the ANAF fallback above, labels every result with its source, and returns the consultation number when a requester VAT is set. Free for low volume – 100 checks a month, no card – and low cost above that. Register and the fallback stops being your problem.
  2. Queue retries against VIES without a fallback. Simplest to write. Fine only if your flow can tolerate a ‘we’ll get back to you’ UX.
  3. Build the ANAF integration yourself. That means handling the mandatory date parameter, the 100-CUI batch and one-request-per-second limits, and the VIES-vs-ANAF status mismatch in your own code. Doable, but it is code you keep maintaining.

ANAF enrichment on a VIES success

ANAF is also used the other way round. When VIES answers successfully, vatnode makes a best-effort call to ANAF to add company data VIES does not provide:

  • companyRegistrationDate – ANAF’s registration date, from which companyAgeYears is derived.
  • companyForm – the legal form. Where the Romanian form is in vatnode’s lookup table it is mapped to an English label, otherwise the Romanian text is returned in Title Case (for example Societate Comercială Cu Răspundere Limitată).
  • industryDescription – the CAEN (NACE) activity code mapped to an English label.

Any of the three can be null. The enrichment never changes valid or source: the verdict still comes from VIES. The set of countries with a national fallback or enrichment changes over time, so the current list is at /docs/coverage.

Full working example with the vatnode API

const res = await fetch('https://api.vatnode.dev/v1/vat/RO12345678', {
  headers: { Authorization: `Bearer ${process.env.VATNODE_API_KEY}` },
})

if (!res.ok) {
  const { error } = await res.json()
  throw new Error(`VAT check failed: ${error.code}`)
}

const data = await res.json()
// {
//   "valid": true,
//   "vatId": "RO12345678",
//   "countryCode": "RO",
//   "companyName": "EXEMPLU SOFTWARE SRL",        // typically present, not guaranteed
//   "companyAddress": "STR. EXEMPLU NR. 1, BUCUREŞTI", // same
//   "companyRegistrationDate": "2011-03-02",       // ANAF enrichment, can be null
//   "companyForm": "Societate Comercială Cu Răspundere Limitată", // can be null
//   "industryDescription": null,                   // can be null
//   "registryCode": null,
//   "registryCodeName": null,
//   "taxId": "12345678",
//   "taxIdName": "cod unic de înregistrare",
//   "registryPrivacy": false,
//   "commercialName": null,
//   "companyStatus": null,
//   "secondaryActivities": [],
//   "companyAgeYears": 15,
//   "website": null,
//   "verifiedAt": "2026-11-18T08:30:00.000Z",
//   "checkId": "019d2a89-a5d9-7b97-b710-57b84604de2b",
//   "countryName": "Romania",
//   "countryVat": { "vatNumberFormat": "RO + 2–10 digits", "vatNumberPattern": "^RO\\d{2,10}$", ... },
//   "consultationNumber": "WAPIAAAAX...",  // only when a requester VAT is set (dashboard → Account details)
//   "specialTerritory": null,
//   "source": "VIES"
// }

RO12345678 is a synthetic number and the values above are illustrative: they show the response shape for a valid Romanian check, not what VIES says about this number. It fails the checksum, so don’t expect a real lookup to confirm it. taxId is the digits after RO and taxIdName is the local name of that identifier. registryCode stays null, because the trade register number is a separate identifier that a check neither derives nor fetches.

The field that matters for your logic is source. Branch on whether it is VIES, not on whether it is ANAF_RO:

type RoVerdict = 'confirmed' | 'rejected' | 'provisional' | 'unconfirmed'

function classifyRomanianCheck(data: { valid: boolean; source: string }): RoVerdict {
  if (data.source === 'VIES') {
    return data.valid ? 'confirmed' : 'rejected'
  }
  // ANAF_RO, and also CACHE: a cache hit reports source "CACHE" and
  // does not say which source produced the cached answer
  return data.valid ? 'provisional' : 'unconfirmed'
}

Results are cached for 15 minutes when valid and 5 minutes when invalid, and a cache hit reports source: "CACHE" with a null consultation number. CACHE hides where the answer came from, so treat anything other than VIES as provisional in your own logic: queue a VIES re-check and don’t rely on the result for reverse charge until it comes back as confirmed. What a provisional result means for the order and the invoice is a decision for you and your tax adviser. When a requester VAT is set, cache reads are skipped, so you get a fresh VIES call each time. This article is informational, not legal or tax advice.

Test keys (vat_test_ prefix) accept only the reserved XX fixture numbers and successful test responses carry source: "VIES", so they won’t produce an ANAF_RO or CACHE result. Cover those two branches with a mocked response in your unit tests; the fixtures are listed in test mode.

What to store, and personal data for individuals

For every check, store the checkId, verifiedAt, valid, source and, when present, the consultationNumber, plus the name and address the response returned. The source is what lets you tell a VIES confirmation from a provisional one months later. The audit trail guide covers what an auditable record looks like, and national tax ID from a VAT number explains what taxId is and is not.

For a sole trader or a liberal professional, the identifier can be based on their CNP and companyName is typically their own name. Treat any 13-digit value, and the name attached to it, as personal data under the GDPR. The CNP is also a national identification number, and Romanian law (art. 4 of Law 190/2018, adopted under art. 87 GDPR) sets extra conditions for processing it, particularly when you rely on legitimate interest. Collect it only where you need it, keep it out of logs and analytics, and give it its own retention period instead of inheriting a default. vatnode itself rejects a 13-digit RO value as INVALID_FORMAT, so the check will not return one, but your own forms and exports may still collect it.

Error handling

The vatnode API returns explicit error codes:

  • INVALID_FORMAT (400) – the string isn’t a well-formed RO VAT ID (including a 13-digit value). Your input; surface it inline, don’t retry.
  • INVALID_REQUESTER (422) – your configured requester VAT number was rejected by VIES. Fix it in dashboard Account details.
  • RATE_LIMITED (429) – you’ve spent your quota on a plan without overage. Retryable on a longer horizon, or see pricing for plans with more requests.
  • VIES_UNAVAILABLE (503) – the Romanian node (or VIES itself) is down and no fallback answered. Transient – queue a retry, never mark the number invalid.
  • VIES_ERROR (502) / UPSTREAM_TIMEOUT (504) – transient upstream faults. Retry with backoff. With a requester VAT set, a 502 VIES_ERROR is also what you get when VIES answered valid but issued no consultation number; that request isn’t counted against your quota and is safe to retry.
  • VIES_ERROR (403) – VIES reports the VAT ID or vatnode’s IP as blocked (VAT_BLOCKED / IP_BLOCKED). Not a verdict on the number, but not transient either – don’t retry in a loop; alert and review.
  • AUDIT_WRITE_FAILED (502) – the check ran but its audit row couldn’t be stored, so no checkId was issued. Not billed, safe to retry.
  • INTERNAL_ERROR (500) – retry, alert if it persists.

If you have no requester VAT set, a transient VIES failure can resolve into an ANAF_RO answer rather than an error, so your code needs the source branch above as much as the error branch. If you do have one set, expect VIES_UNAVAILABLE instead and retry with exponential backoff (500ms, 2s, 5s), then queue the check for a background re-run rather than blocking checkout. Without a requester, when ANAF can’t answer either, the same VIES_UNAVAILABLE or UPSTREAM_TIMEOUT is served from a short error cache for 60 seconds, so space those retries over at least a minute. Full code reference at /docs/errors; retry table in handling VIES error codes. For the wider pattern of designing around VIES, see the VIES alternative guide and the Node.js VAT validation guide.

FAQ

What does a Romanian VAT number look like?

It is the prefix RO followed by 2 to 10 digits, the CUI (cod unic de înregistrare) of a VAT-registered entity. The last digit of the CUI is a check digit. vatnode accepts the pattern RO plus 2 to 10 digits and rejects anything else as INVALID_FORMAT. A match means the string is well-formed, not that the business exists or is VAT-registered.

How do I check a Romanian VAT number, and what happens when VIES is down?

Normalise the string, check the format, then query VIES, which is the only source that can issue a consultation number. When the Romanian node is down and your account has no requester VAT set, vatnode asks the ANAF public service instead and labels the result source ANAF_RO. That result reports whether ANAF lists the entity as a VAT payer, which is useful as a provisional answer but is not a VIES confirmation. With a requester VAT set, vatnode returns the VIES error and you retry later.

Is the CUI the same as the Romanian VAT number?

Not always. The CUI is the tax identification code of an entity registered in the trade register. The VAT number is RO plus that code only if the entity is registered for VAT, so a company can hold a CUI and have no Romanian VAT number. The trade register number (J40/1234/2005 style) is a different identifier and is not a VAT number.

Validate Romanian VAT numbers without wiring up ANAF yourself

One call runs the VIES check for Romania and labels the result with its source. When VIES is down and no requester VAT is set, it falls back to ANAF. With a requester VAT configured, it returns the consultation number. Free plan, 100 requests/month.

Get a free API key · API reference · Romania VAT API reference