Validate and generate credit card numbers using Luhn algorithm
Validate and generate credit card numbers using the Luhn algorithm instantly with our free online credit card validator. This tool helps developers test payment systems by validating card number checksums and generating valid test numbers. Simply enter a card number or generate one for testing.
This tool is for educational and testing purposes only. Generated numbers are valid according to the Luhn algorithm but are NOT real credit card numbers and should never be used for actual transactions. Validating a number does not mean it's a real, active card.
The Luhn algorithm (also known as the modulus 10 algorithm) is a checksum formula used to validate credit card numbers. It detects simple errors in the number sequence but does not verify if a card is real, active, or has funds.
Luhn algorithm validator checks if numbers pass the Luhn checksum, commonly used for credit cards, IMEI numbers, and identification numbers. Also generates valid Luhn numbers by calculating the correct check digit for any numeric sequence.
From rightmost digit, double every second digit. If doubled value > 9, subtract 9. Sum all digits. Valid if sum ends in 0 (mod 10 = 0). For check digit generation: calculate sum with placeholder, find digit that makes sum divisible by 10.
Luhn algorithm (mod 10): 1) Double alternating digits from right, 2) If result > 9, subtract 9 (or sum digits), 3) Sum all digits, 4) Valid if total % 10 === 0. Detects single digit errors and adjacent transpositions. Not cryptographically secure.
Verify card numbers before processing.
4111111111111111 (valid Visa test)Check mobile device identifiers.
Generate valid test numbers.
Validate numeric identifiers in databases.
// Validate a number using Luhn algorithm
function luhnValidate(number) {
const digits = String(number).replace(/\D/g, '').split('').map(Number);
let sum = 0;
for (let i = digits.length - 1; i >= 0; i--) {
let digit = digits[i];
// Double every second digit from right
if ((digits.length - i) % 2 === 0) {
digit *= 2;
if (digit > 9) digit -= 9;
}
sum += digit;
}
return sum % 10 === 0;
}
// Generate check digit
function luhnCheckDigit(number) {
const digits = String(number).replace(/\D/g, '').split('').map(Number);
digits.push(0); // Placeholder for check digit
let sum = 0;
for (let i = digits.length - 1; i >= 0; i--) {
let digit = digits[i];
if ((digits.length - i) % 2 === 0) {
digit *= 2;
if (digit > 9) digit -= 9;
}
sum += digit;
}
return (10 - (sum % 10)) % 10;
}
// Generate complete valid number
function generateLuhnNumber(prefix, length) {
let number = prefix;
// Fill with random digits (leaving space for check digit)
while (number.length < length - 1) {
number += Math.floor(Math.random() * 10);
}
// Add check digit
number += luhnCheckDigit(number);
return number;
}
// Examples
console.log(luhnValidate('4111111111111111')); // true (Visa test)
console.log(luhnValidate('4111111111111112')); // false
console.log(luhnCheckDigit('411111111111111')); // 1
console.log(generateLuhnNumber('4', 16)); // Random valid Visa-likeComplete Luhn implementation: validation, check digit calculation, and number generation.
Use Luhn validator to check credit card numbers, IMEI, or other Luhn-protected identifiers before processing. Use generator for test data only.
No. Luhn only checks mathematical validity. A valid Luhn number could still be invalid (expired, wrong issuer, fake). Always verify with payment processor.
Validate css syntax and structure. Real-time validation with detailed error messages. Essential for developers, QA testers, and data analysts.
Validate javascript syntax and structure. Real-time validation with detailed error messages. Essential for developers, QA testers, and data analysts.
Validate tfn syntax and structure. Real-time validation with detailed error messages. Essential for developers, QA testers, and data analysts.