Luhn algorithm — ISO/IEC 7812-1.
Used by: credit cards, CA SIN, FR SIREN/SIRET, IT P.IVA, IL TZ/HP, ZA ID, and several IDs that document the algorithm as "Luhn variant".
Algorithm:
Public-domain mathematical algorithm.
Digit-only string including the trailing check digit. Non-digit input is rejected (returns false) — separators must be stripped by the caller.
false
true when the digits satisfy the Luhn property (sum mod 10 = 0).
true
import { luhnValid } from "nationid/algorithms";luhnValid("79927398713"); // true (canonical Luhn specimen)luhnValid("79927398710"); // falseluhnValid("12-34"); // false (non-digit characters) Copy
import { luhnValid } from "nationid/algorithms";luhnValid("79927398713"); // true (canonical Luhn specimen)luhnValid("79927398710"); // falseluhnValid("12-34"); // false (non-digit characters)
Luhn algorithm — ISO/IEC 7812-1.
Used by: credit cards, CA SIN, FR SIREN/SIRET, IT P.IVA, IL TZ/HP, ZA ID, and several IDs that document the algorithm as "Luhn variant".
Algorithm:
Public-domain mathematical algorithm.