What this tool is for
If you build a checkout, subscription or donation form, you need to validate card numbers on the client before they ever reach your payment provider: catch typos early, show the right card logo and format the number as the user types. This credit card validator lets developers and QA testers check numbers against the same rules your form should apply, using the test card numbers that payment providers publish for exactly this purpose.
Important: a "valid" result only means the number is well-formed. It says nothing about whether a card exists, is active or has funds, and it cannot and does not contact any bank or card network. Only a payment processor can authorize a card.
Three checks in this credit card validator
- Network (IIN/BIN prefix) – the leading digits identify the network: Visa starts with 4, Mastercard with 51–55 or 2221–2720, American Express with 34 or 37, Discover with 6011, 644–649 or 65, and so on. Supported networks include Visa, Visa Electron, Mastercard, American Express, Discover, Diners Club, JCB, UnionPay, Maestro, RuPay and Mir.
- Length – each network allows specific lengths, such as 15 digits for Amex, 16 for Mastercard and 13, 16 or 19 for Visa.
- Luhn checksum – the last digit is a check digit that catches most single-digit typos and swapped neighboring digits.
How the Luhn algorithm works
Starting from the rightmost digit and moving left, double every second digit; if doubling gives a number above 9, subtract 9. Add all digits together. If the total is a multiple of 10, the number passes. For 4111 1111 1111 1111, the sum is 30, so it passes. Change any single digit and the sum is no longer a multiple of 10.
function luhn(digits) {
let sum = 0, double = false;
for (let i = digits.length - 1; i >= 0; i--) {
let d = Number(digits[i]);
if (double) { d *= 2; if (d > 9) d -= 9; }
sum += d;
double = !double;
}
return sum % 10 === 0;
}
Test numbers for development
Payment providers such as Stripe, Adyen, PayPal/Braintree and others publish test card numbers that pass these checks but only work in their sandbox environments, for example 4111 1111 1111 1111 (Visa), 5555 5555 5555 4444 (Mastercard) and 3782 822463 10005 (Amex). Use your provider's documented test numbers in development and never use real customer card data in test systems.
Example output:
Card number Brand Result
4111 1111 1111 1111 Visa ✔ valid
3782 822463 10005 American Express ✔ valid
4111 1111 1111 1112 Visa ✘ invalid — fails the Luhn checksum
Masking
With masking enabled, only the first six and last four digits are shown (4111 11•• •••• 1111), matching the display rules commonly used under PCI DSS. Use it when you take screenshots for bug reports or documentation.
Privacy
All checks run in JavaScript in your browser; numbers are never transmitted or stored. Even so, do not paste real card numbers into any website you do not need to. For generating other kinds of test data, see the regex-based data generator, and for API experiments with a payment sandbox, the API tester.