Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Luhn algorithm work for all mainstream credit cards? (Discover, Visa, Mastercard, Amex)

Tags:

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.

like image 304
Brian Webster Avatar asked Oct 22 '11 21:10

Brian Webster


People also ask

Does AMEX use Luhn algorithm?

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.

Do all credit cards use Luhn algorithm?

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.

Does Mastercard use Luhn algorithm?

Luhn is known because MasterCard, American Express (AMEX), Visa and all credit cards use it.

What algorithm is used for credit cards?

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.


2 Answers

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:

  • Diners Club enRoute
  • China UnionPay

Validate with Luhn 2:

  • American Express
  • Bankcard
  • Diners Club Carte Blanche
  • Diners Club International
  • Diners Club United States & Canada
  • Discover Card
  • InstaPayment
  • JCB
  • Laser
  • Maestro
  • Dankort
  • MasterCard
  • Solo
  • Switch
  • Visa
  • Visa Electron
like image 124
John Haugeland Avatar answered Oct 05 '22 08:10

John Haugeland


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:

  • VISA debit / credit
  • VISA Electron
  • VISA Delta
  • MasterCard
  • AMEX
  • Maestro
  • Switch
  • Solo
  • Diners Club
  • Discover
  • JCB
like image 22
LazyOne Avatar answered Oct 05 '22 10:10

LazyOne