nationid - v2.2.1
    Preparing search index...

    Function luhnValid

    • 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:

      1. From the rightmost digit, double every second digit.
      2. If doubling produces a 2-digit number, sum its digits (or subtract 9).
      3. Sum all digits.
      4. Number is valid iff sum is divisible by 10.

      Public-domain mathematical algorithm.

      Parameters

      • digits: string

        Digit-only string including the trailing check digit. Non-digit input is rejected (returns false) — separators must be stripped by the caller.

      Returns boolean

      true when the digits satisfy the Luhn property (sum mod 10 = 0).

      import { luhnValid } from "nationid/algorithms";

      luhnValid("79927398713"); // true (canonical Luhn specimen)
      luhnValid("79927398710"); // false
      luhnValid("12-34"); // false (non-digit characters)