Learn More
How card number validation works
Every card number carries its own integrity check. Validating the structure before a transaction is sent catches typos and formatting mistakes that would otherwise come back as an avoidable decline.
What is card number validation?
Card number validation checks that a Primary Account Number (PAN) is structurally correct: the network prefix is recognized, the length matches that network, and the Luhn checksum resolves. It confirms the number is well-formed, not that the account exists or has funds.
A card number is not a random string. The leading digits identify the issuing network, the length is fixed per network, and the final digit is a checksum calculated from every digit before it.
Because all three properties can be checked locally, a mistyped number can be caught in the checkout form itself, before it ever reaches an acquirer. That saves a round trip, avoids a decline on the customer record, and keeps authorization rates cleaner.
Structural validation is not an authorization. A number that passes every check here can still be declined for insufficient funds, a block, or an expired card, since those depend on the issuer.
How this validator checks a number
Detect the card network
The leading digits are matched against published network ranges, for example 4 for Visa, 51-55 and 2221-2720 for Mastercard, 34 and 37 for Amex.
Verify the length
Each network issues numbers of specific lengths. Amex is 15 digits, Mastercard is 16, and Visa can be 13, 16, or 19.
Run the Luhn checksum
Every second digit from the right is doubled, values above nine have nine subtracted, and the total must divide evenly by ten.
Report the result
A number is reported valid only when the network is recognized, the length matches that network, and the checksum resolves.
Common validation failures
| Symptom | Usual cause |
|---|---|
| Luhn check fails | A single mistyped digit, or two adjacent digits transposed. |
| Length not valid | Digits missing or duplicated, often from a copy and paste that dropped a character. |
| Unrecognized network | A test number, a non-card number, or a regional scheme outside the ranges listed above. |
| Valid here, declined live | Structure is fine; the decline is an issuer decision such as funds, fraud rules, or an expired card. |