A lightweight, zero-dependency, and universal TypeScript library to validate Tax IDs (Identification Numbers)
npm install validator-tax-idA lightweight, zero-dependency, and universal TypeScript library to validate Tax IDs (Identification Numbers)
It uses precise mathematical algorithms to verify the integrity of the document number and follow guides of the country governments





| Country | Code | Documents Supported | Algorithm |
| ----------- | ---- | ------------------------------ | ------------------ |
| 🇪🇸 Spain | es | DNI, NIE, CIF | Module 23 |
| 🇵🇹 Portugal | pt | NIF (Personal) | Module 11 |
| 🇫🇷 France | fr | SIREN, SIRET, NIR | Luhn + Mod.97 |
| 🇩🇪 Germany | de | SteuerIdNr, VAT Number, W-IdNr | ISO 7064 Mod 10,11 |
- 🚀 Lightweight: Zero external dependencies.
- 🔒 Type-Safe: Written in TypeScript with full type definitions.
- 🌍 Universal: Works in Node.js, React, Vue, Next.js, and Browsers (Legacy Script Tag).
- ⚡ Tree-shakeable: Only import what you need (if using advanced exports).
``bash`
npm install validator-tax-idor
yarn add validator-tax-idor
pnpm add validator-tax-id
The main function validateIdentification takes two arguments: the country code (ISO 3166-1 alpha-2) and the value to validate.
`typescript
import { validateIdentification } from "validator-tax-id";
// 🇪🇸 Spain (ES)
validateIdentification("es", "12345678Z"); // true (DNI)
validateIdentification("es", "X1234567L"); // true (NIE)
validateIdentification("es", "A58818501"); // true (CIF)
// 🇵🇹 Portugal (PT)
validateIdentification("pt", "232013969"); // true (NIF)
// 🇫🇷 France (FR)
validateIdentification("fr", "443061841"); // true (SIREN)
// 🇩🇪 Germany (DE)
validateIdentification("de", "86095742719"); // true (SteuerIdNr)
validateIdentification("de", "DE136695976"); // true (VAT Number)
`
For better tree-shaking and direct access, use individual validators:
`typescript
import {
// Spain
validateDNI,
validateNIE,
validateCIF,
// France
validateSIREN,
validateSIRET,
validateNIR,
// Portugal
validateNIF,
// Germany
validateSteuerIdNr,
validateVatNumber,
validateWidnr,
} from "validator-tax-id";
// 🇪🇸 Spain - Direct validation
validateDNI("12345678Z"); // true
validateNIE("X1234567L"); // true
validateCIF("A58818501"); // true
// 🇫🇷 France - Direct validation
validateSIREN("443061841"); // true
validateSIRET("44306184100047"); // true
validateNIR("188057512301180"); // true
// 🇵🇹 Portugal - Direct validation
validateNIF("123456789"); // true
// 🇩🇪 Germany - Direct validation
validateSteuerIdNr("86095742719"); // true
validateVatNumber("DE136695976"); // true
validateWidnr("136695976"); // true
`
If you don't know the specific document type:
`typescript
import {
validateES,
validateFR,
validatePT,
validateDE,
} from "validator-tax-id";
validateES("12345678Z"); // true (auto-detects DNI)
validateES("A58818501"); // true (auto-detects CIF)
validateFR("443061841"); // true (auto-detects SIREN)
validatePT("123456789"); // true
validateDE("86095742719"); // true (auto-detects SteuerIdNr)
validateDE("DE136695976"); // true (auto-detects VAT Number)
`
- country: CountryCode ('es' | 'pt' | 'fr' | 'de') - The ISO code of the country.string
- value: - The document string to validate.boolean
- Returns: (true if valid, false` otherwise).
_Note: The validator sanitizes the input automatically (removes spaces, hyphens, and is case-insensitive)._
If this library helped you, consider buying me a coffee ☕

MIT