Skip to main content

Checksum validators

The detectors use these validators to confirm what they find. anonyma/validators exports them, for your own form validation or detectors:

import { cnpjChecksum, ibanMod97, luhn, nhsMod11 } from "anonyma/validators";

luhn("4111111111111111"); // true
ibanMod97("GB82WEST12345698765432"); // true
nhsMod11("943-476-5919"); // true
cnpjChecksum("12.ABC.345/01DE-35"); // true — alphanumeric CNPJ
FunctionAlgorithmChecks
luhnLuhn (ISO/IEC 7812)Payment cards
ibanMod97MOD-97 (ISO 13616)IBANs
abaRoutingChecksum3-7-1 weightsUS bank routing numbers
npiChecksumLuhn behind prefix 80840US National Provider Identifiers
deaChecksumDEA check digitUS prescriber registrations
vinChecksumPosition-9 check digitVehicle identification numbers
imeiChecksumLuhnMobile device identities
cpfChecksumMod-11Brazilian CPF
cnpjChecksumMod-11Brazilian CNPJ, numeric or alphanumeric
pixPayloadChecksumCRC-16PIX "copia e cola" payloads
nhsMod11Mod-11UK NHS numbers
ninoValidFormat rulesUK National Insurance numbers
bsnChecksumEleven testDutch BSN
ptNifChecksumMod-11Portuguese NIF
spanishIdChecksumMod-23 letterSpanish DNI and NIE
italianFiscalCodeChecksumCheck letterItalian codice fiscale
frNirChecksum97 − n mod 97French NIR
swedishPersonnummerChecksumLuhnSwedish personnummer
verhoeffVerhoeffIndian Aadhaar
aadhaarFormatFormat rulesIndian Aadhaar
chineseResidentIdChecksumISO 7064 MOD 11-2Chinese resident identity numbers
australianTfnChecksumWeighted mod-11Australian tax file numbers

By name​

CHECKSUMS holds every validator by name — "luhn", "cnpj", "aba-routing", … — and a pipeline pattern names the one its matches must pass:

compilePipeline({
patterns: [{ source: String.raw`\b\d{9}\b`, category: "routing", validator: "aba-routing" }],
});

Checksums lists the names; it is generated from the code. A plugin can also attach a validator to a built-in category.