A Luhn check test script validates a numeric string against the Luhn algorithm, the mod-10 checksum used to catch mistyped digits in payment card numbers, IMEIs, and several national identification formats. It answers one question quickly and deterministically: does this sequence of digits carry a valid check digit? That makes it useful in checkout form validation, automated test suites, and data cleanup jobs where obvious typos should be rejected long before anything reaches a payment gateway.
Key Features
- Single-file mod-10 checksum implementation with no runtime dependencies
- Accepts raw digits, spaces, or dashes and normalizes input before checking
- Returns a boolean result plus the computed check digit so failures are easy to debug
- Ships with fixtures for valid sample numbers and deliberately corrupted ones
- Covers edge cases: empty strings, single digits, letters, and leading zeros
- Runs under Node 18+, in modern browsers, and inside CI pipelines with no configuration
- Optional command-line wrapper for validating a list of numbers piped from a file
- Configurable minimum and maximum length plus optional prefix filters
Implementation and Specs
The script is written as plain JavaScript using ES modules and stays under roughly 120 lines, so it is easy to audit and paste into an existing project. It has zero runtime dependencies, is side-effect free, and never stores, logs, or transmits the values it receives. A companion JavaScript test suite runs under Jest or Vitest and exercises both the passing and failing paths, including random digit corruption, so you can wire it into a build step and trust the signal. TypeScript type declarations are included for teams that want them.
luhn algorithm verification test
Delivery, Updates, and Refunds
This is a digital download, so there is nothing to ship. A download link is delivered by email immediately after checkout, and every future patch to the script is free for existing buyers. If it does not fit your project, request a refund within 30 days and it will be processed without a follow-up questionnaire.
What does a Luhn check actually prove?
It proves that the digits are internally consistent with their own check digit, which catches single-digit typos and most adjacent transpositions. It does not prove that an account exists, is active, or is authorized for any transaction.
Can it tell me whether a card number is real?
No. A Luhn pass only means the formatting is valid. Confirming an account requires a payment gateway authorization, and full card numbers should never be retained in logs or storage after that step.
Does it work for numbers other than cards?
Yes. Any identifier that uses a mod-10 check digit works, including IMEI numbers, some national ID schemes, and many internal account or serial numbering systems.