Reference: Luhn Algorithm
The Luhn Algorithm is a great way to quickly verify that the user typed their CC # in correctly.
However, I am concerned that there may be a subset of mainstream credit cards that do not use Luhn-Algorithm-friendly numbers.
I do have logging in place in our application to detect a pattern in all Luhn-Algorithm-rejections, but I'd rather know definitively.
Credit card companies, including American Express, Visa, Mastercard and Discover, use the Luhn algorithm. It does not verify any other information on a credit card, including whether the card's date is valid.
The formula is widely used in validating credit card numbers, as well as other number sequences such as government Social Security Numbers (SSNs). Today, the Luhn Algorithm is an essential component in the electronics payments system and is used by all major credit cards.
Luhn is known because MasterCard, American Express (AMEX), Visa and all credit cards use it.
Luhn's algorithm. Luhn's algorithm determines whether or not a credit card number is valid. For a given credit card number: Double the value of every other digit from right to left, beginning with the second to last digit.
Almost.
China UnionPay and one kind of Diners Club card (enRoute) do not use Luhn validation. (LazyOne’s answer is wrong about Diners Club.)
Nearly everyone else does.
Citing Wikipedia's 'Bank card' page:
Don't validate at all:
Validate with Luhn 2:
Yes -- it works for all mainstream card types.
I have a custom PHP class to handle card data that was compiled from various "validate card number" and alike functions from few programming languages + information from Wikipedia & some Payment Processing systems. It successfully validates test card numbers (every payment system has few of such numbers) for these card types:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With