Validate Danish VAT Numbers (CVR) in Node.js
25 Nov 2026

A Danish VAT number is DK followed by 8 digits, and in the usual case those digits are the business’s CVR number. Check the format, run the mod-11 check as a typo hint, then let VIES decide, because Denmark has no national fallback when the VIES node is down. This post covers the Node.js side. For the endpoint’s general behaviour see the Denmark VAT API reference, and for a one-off lookup use the Danish VAT checker.
What a Danish VAT number looks like
The Danish VAT ID (momsnummer, from moms, the Danish VAT) is:
DK– the VIES country prefix- 8 digits – in the usual case, the CVR number
vatnode enforces the pattern ^DK\d{8}$. Danish invoices commonly print the number as DK 12345678, with a space, so strip whitespace, dots and dashes before matching:
const DK_VAT_PATTERN = /^DK\d{8}$/
function normaliseDanishVatId(input: string): string | null {
const cleaned = input.replace(/[\s.\-]/g, '').toUpperCase()
return DK_VAT_PATTERN.test(cleaned) ? cleaned : null
}
normaliseDanishVatId('DK 12345678') // → 'DK12345678'
normaliseDanishVatId('12345678') // → null (no prefix)
normaliseDanishVatId('DK1234567') // → null (7 digits)
The standard Danish rate in vatnode’s rates dataset is 25%. A string that matches the pattern is only well-formed input. Format vs valid covers the difference.
CVR number vs SE number vs VAT registration
Three things get mixed up here.
- The CVR number is the business’s number in the Central Business Register (Det Centrale Virksomhedsregister), run by the Danish Business Authority (Erhvervsstyrelsen). VAT itself is administered by the Danish Tax Agency (Skattestyrelsen).
- An SE number identifies an administrative unit of a business. A business can have one or more. Where it has only one, Statistics Denmark notes that the SE number is the same as the CVR number. The Danish Tax Agency’s VAT number search takes either a CVR or an SE number, and notes that where a business has SE numbers, the CVR number is not always VAT-registered.
- VAT registration is separate from having a CVR. A business can have a CVR number without being VAT-registered, for example below the registration threshold or with VAT-exempt activity.
A CVR number and an SE number are both 8 digits. Validate the exact number the customer gave you, and don’t assume that DK plus a CVR you found elsewhere is registered for VAT.
The mod-11 check in Node.js
The Danish Business Authority’s modulus-11 page (archived in 2012) documents the check for CVR numbers, and Statistics Denmark confirms that the 8th digit is a check digit computed with modulus 11:
- Multiply the 8 digits by the weights
2, 7, 6, 5, 4, 3, 2, 1. - Add the products.
- The sum must be divisible by 11.
The 8th digit is the check digit, calculated from the first seven. The archived page states that CVR numbers satisfy this check. I could not find an authoritative source saying SE numbers follow the same rule, so treat mod-11 as a soft hint: warn the user about a likely typo, but don’t hard-reject on it, and let VIES give the verdict.
const CVR_WEIGHTS = [2, 7, 6, 5, 4, 3, 2, 1]
function cvrWeightedSum(digits: string): number {
return CVR_WEIGHTS.reduce((sum, weight, i) => sum + Number(digits[i]) * weight, 0)
}
function passesMod11(vatId: string): boolean {
return cvrWeightedSum(vatId.slice(2)) % 11 === 0
}
// 12345678: 2 + 14 + 18 + 20 + 20 + 18 + 14 + 8 = 114, 114 mod 11 = 4
passesMod11('DK12345678') // → false
12345678 is synthetic and fails on purpose; the examples here show only failing numbers, so none is a valid CVR number. A passing result only says the digits are consistent. The vatnode API does not run this check: its server validates the DK + 8 digit pattern and then asks VIES. Run it on your side instead, in a checkout form, to catch a mistyped digit before a network call.
Calling the vatnode API
Format-valid input goes to VIES. This example uses the invented number DK38415927, which fails mod-11 (weighted sum 149, remainder 6), so it is not a valid CVR number. Nordlys Kode ApS is invented too, and the values are illustrative, not what VIES says about any real business. A free plan key (100 requests a month) is enough to try the call with a real number.
const vatId = 'DK38415927'
const res = await fetch(`https://api.vatnode.dev/v1/vat/${vatId}`, {
headers: { Authorization: `Bearer ${process.env.VATNODE_API_KEY}` },
signal: AbortSignal.timeout(20_000),
})
if (!res.ok) {
const body = (await res.json().catch(() => null)) as { error?: { code?: string } } | null
throw new Error(`VAT check failed: ${body?.error?.code ?? res.status}`)
}
const data = await res.json()
// {
// "valid": true,
// "vatId": "DK38415927",
// "countryCode": "DK",
// "companyName": "Nordlys Kode ApS",
// "companyAddress": "Havnegade 12\n1058 København K",
// "companyRegistrationDate": "2014-06-02", // CVR enrichment, can be null
// "companyForm": "Private limited company (ApS)", // can be null
// "industryDescription": "Computer programming activities", // can be null
// "registryCode": "38415927",
// "registryCodeName": "CVR-nummer",
// "taxId": "38415927",
// "taxIdName": "CVR-nummer",
// "registryPrivacy": false,
// "website": null,
// "commercialName": null,
// "companyStatus": "active", // register status, can be null
// "secondaryActivities": [],
// "companyAgeYears": 12,
// "verifiedAt": "2026-11-25T08:30:00.000Z",
// "checkId": "019d2a89-a5d9-7b97-b710-57b84604de2b",
// "countryName": "Denmark",
// "countryVat": { "vatName": "Moms", "standardRate": 25, ... },
// "consultationNumber": null, // set only with a requester VAT
// "specialTerritory": null,
// "source": "VIES"
// }
Two fields in this response need handling:
- The address contains line breaks. VIES returns Danish addresses with
\nbetween lines, such asStreet 1\n1234 City. Split it on\nbefore you print it on an invoice or drop it into a single-line field, or the street and the city run together. registryCodeandtaxIdare the 8 digits read off the VAT number, both labelledCVR-nummer. If the business is VAT-registered under an SE number, those digits are the SE number and the label still says CVR-nummer, because the format cannot distinguish them. See national tax ID from a VAT number.
A consultationNumber is returned only when you have set a requester VAT number once in dashboard Account details, and then the cache is bypassed so VIES answers each call. It is evidence of the check you made, not tax advice and not by itself proof that a tax treatment applies. The consultation number explainer covers it in full.
When VIES DK is down (no national fallback)
The Danish node is not always available. For current status see VIES status for Denmark.
Some countries have a national source that vatnode can ask when VIES fails, and /docs/coverage lists which ones. Denmark is not among them for validity, because the CVR is a company register, not a VAT register. A company’s presence in it does not establish VAT registration, so answering from it during an outage would produce false positives. vatnode doesn’t do that.
So during an outage you get an error, not a degraded answer:
VIES_UNAVAILABLE(503) orUPSTREAM_TIMEOUT(504) when the node is down or slow.VIES_ERROR(502) for protocol faults.
Without a requester VAT set, a VIES_UNAVAILABLE or UPSTREAM_TIMEOUT is cached for 60 seconds, so retries inside that window return the same error. A check that ends in an error does not count against your quota. For Denmark, source is always VIES or CACHE. A cache hit returns source: "CACHE" with a null consultation number, and valid results are cached for 15 minutes and invalid ones for 5. Treat CACHE as not being a fresh VIES answer:
type DkVerdict = 'confirmed' | 'rejected' | 'cached-valid' | 'cached-invalid'
function classifyDanishCheck(data: { valid: boolean; source: string }): DkVerdict {
if (data.source === 'VIES') {
return data.valid ? 'confirmed' : 'rejected'
}
// CACHE: an earlier answer, not a fresh VIES response and no consultation number
return data.valid ? 'cached-valid' : 'cached-invalid'
}
If you need a fresh answer for a document you will keep, re-check once the cache entry has expired, or set a requester VAT, which bypasses the cache. The VIES downtime guide and VIES vs national VAT databases cover designing around outages.
CVR register enrichment
After every VIES answer, valid or invalid, vatnode makes a best-effort lookup through a third-party interface to the Danish Central Business Register. It can add exactly four fields:
companyRegistrationDate– an ISO date, from whichcompanyAgeYearsis derived.companyForm– an English label from a fixed table, such asPrivate limited company (ApS),Public limited company (A/S)orSole trader. If the form is not in the table, you get the Danish form name.industryDescription– the NACE code mapped to English, falling back to the Danish description.companyStatus–active,ceasedorbankrupt.
Any of the four can be null, and often are, so write code that handles that. Two rules apply when you use them:
companyStatusis the company-register status, not VAT status. It can disagree withvalidin either direction, for example a ceased company that VIES still lists, or an active company that is not VAT-registered. Don’t derive one from the other.- Enrichment never changes
validorsource. The verdict comes from VIES.
companyName and companyAddress come from VIES, not from the register. For Denmark commercialName is null, secondaryActivities is empty and registryPrivacy is false. The company data enrichment post covers the idea in general.
function describeCompany(data: {
companyName: string | null
companyForm: string | null
companyStatus: 'active' | 'ceased' | 'bankrupt' | null
}): string {
const form = data.companyForm ?? 'form unknown'
const status = data.companyStatus ?? 'status unknown'
return `${data.companyName ?? 'Unnamed'} (${form}, ${status})`
}
What to store
For every check, keep the checkId, verifiedAt, valid, source and, when present, the consultationNumber, plus the name and address returned. source lets you tell a fresh VIES confirmation from a cached answer months later. The audit trail guide shows what an auditable record looks like.
Sole proprietorships (enkeltmandsvirksomhed) get their own CVR number, separate from the owner’s personal CPR number, which the register does not disclose to private parties. But the registered name is often the owner’s own name. Treat the name, address and register data returned for a sole proprietor as personal data under the GDPR: keep them for a defined purpose and give them a retention period, rather than inheriting a default. This article is informational, not legal or tax advice.
Error handling
The vatnode API returns explicit error codes:
UNAUTHORIZED/INVALID_API_KEY(401) – missing or revoked key. Fix the key, don’t retry.INVALID_FORMAT(400) – the string isn’tDKplus 8 digits. Your input; show it inline, don’t retry.INVALID_REQUESTER(422) – your configured requester VAT number was rejected. Fix it in dashboard Account details.RATE_LIMITED(429) – monthly quota spent on a plan without overage, such as the free plan. See pricing.VIES_UNAVAILABLE(503) /UPSTREAM_TIMEOUT(504) – the Danish node is down or slow, and there is no fallback. Transient: never mark the number invalid.VIES_ERROR(502) – protocol fault, retry with backoff.VIES_ERROR(403) means VIES reports the VAT ID or vatnode’s IP as blocked (VAT_BLOCKED/IP_BLOCKED): not a verdict on the number, and not transient either, so alert and review instead of looping.AUDIT_WRITE_FAILED(502) – the check ran but its audit row couldn’t be stored. Not billed, safe to retry.INTERNAL_ERROR(500) – retry, alert if it persists.
type DkResult = 'valid' | 'invalid' | 'pending'
async function checkDanishVat(vatId: string): Promise<DkResult> {
let res: Response
try {
res = await fetch(`https://api.vatnode.dev/v1/vat/${vatId}`, {
headers: { Authorization: `Bearer ${process.env.VATNODE_API_KEY}` },
signal: AbortSignal.timeout(20_000),
})
} catch {
return 'pending' // network failure or our own timeout: no verdict either
}
if (res.ok) {
const data = (await res.json()) as { valid: boolean }
return data.valid ? 'valid' : 'invalid'
}
const body = (await res.json().catch(() => null)) as { error?: { code?: string } } | null
const code = body?.error?.code ?? `HTTP_${res.status}`
if (code === 'VIES_UNAVAILABLE' || code === 'UPSTREAM_TIMEOUT') {
return 'pending' // no verdict yet: queue a re-check, don't block checkout
}
throw new Error(`VAT check failed: ${code}`)
}
Don’t retry pending in a tight loop. The error is cached for a minute, so an immediate retry gets the same answer back. Queue the check and run it again a few minutes later, with the gap growing on each attempt, and let the order go through in the meantime if your process allows it. Full reference at /docs/errors and in handling VIES error codes. In unit tests, use a test key (vat_test_ prefix): it accepts only the reserved XX fixture numbers (a DK ID sent with a test key returns INVALID_FORMAT), so mock DK responses yourself; fixtures are in test mode.
The same pattern, for other markets, is in the Swedish, Romanian and Polish guides.
FAQ
Is a Danish VAT number the same as the CVR number?
Usually, yes. In the common case the VAT number is DK followed by the 8-digit CVR number of the business. A business can also have SE numbers (administrative units) and be VAT-registered under one of them, and an SE number looks identical to a CVR number. Validate the exact number your customer gave you.
Does passing the mod-11 check mean the business is VAT-registered?
No. Mod-11 only says the 8 digits are internally consistent, which makes it a typo filter. A business can hold a CVR number without being VAT-registered, for example below the registration threshold or with VAT-exempt activity. Only a VIES check tells you whether the number is valid for intra-EU VAT.
What happens when VIES Denmark is down?
vatnode has no national fallback for Denmark, because the CVR is a company register and not a VAT register. You get VIES_UNAVAILABLE (503) or UPSTREAM_TIMEOUT (504). Treat these as transient, retry with backoff, queue a background re-check and never mark the number invalid.
Can I get company data for a Danish VAT number?
VIES normally returns the name and address for a valid Danish number, but treat them as optional. After every VIES answer, vatnode also makes a best-effort lookup that can add the registration date, company form, industry and company-register status. Any of these can be null, so your code must handle missing values.
Validate Danish VAT numbers without writing your own VIES client
One call runs the VIES check for Denmark, labels the result with its source and adds CVR register data when it is available. Free plan, 100 requests/month.