DEV Community

Dev Nestio
Dev Nestio

Posted on

Luhn Algorithm Checker — Validate & Generate Credit Card Numbers

Overview

Luhn Algorithm Checker validates and generates numbers using the Luhn (mod 10) checksum.

🔗 https://devnestio.pages.dev/luhn-checker/

What it validates

Credit cards (Visa, Mastercard, Amex, Discover), IMEI codes, ISIN identifiers, and more.

The algorithm

  1. From the rightmost digit, double every second digit
  2. If doubling > 9, subtract 9
  3. Sum all digits — if sum mod 10 = 0, valid
function luhn(digits) {
  let sum = 0;
  for (let i = 0; i < digits.length; i++) {
    let d = digits[i];
    if (i % 2 === 1) { d *= 2; if (d > 9) d -= 9; }
    sum += d;
  }
  return sum;
}
Enter fullscreen mode Exit fullscreen mode

Features

  • Instant valid/invalid banner with color coding
  • Step-by-step digit breakdown table
  • Generate mode: enter prefix → get correct check digit
  • Card type detection (Visa, Mastercard, Amex, Discover, JCB, Diners)

👉 Try it: https://devnestio.pages.dev/luhn-checker/

Top comments (0)