22

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.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225

3 Answers3

13

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
lxg
  • 12,375
  • 12
  • 51
  • 73
John Haugeland
  • 9,230
  • 3
  • 37
  • 40
  • 2
    The key phrase of the initial question being "mainstream cards".... the odd subset of China Unionpay and Diners Club enRoute would seem to be outside "mainstream" and therefore, LUHN will validate "mainstream cards"/ –  Jul 29 '15 at 15:52
  • Yes, and those are two very common credit cards, admittedly not in the United States. Thank you for your contribution; please have a good day. – John Haugeland Jul 29 '15 at 20:14
  • The Wiki page has changed since your answer. UnionPay now appears to also use the Luhn algorithm to validate card numbers. I have no other source than the Wikipedia article, where this was changed back in March 2015. – reSPAWNed Apr 26 '16 at 08:34
  • 2
    There is a subset of China UnionPay cards that have the Discover logo on them that do pass Luhn validation. I can confirm this from production experience. – dbyoung Dec 21 '16 at 21:04
  • There are also UnionPay cards that don't. Whereas some do, it's not something you can safely count on. – John Haugeland Dec 22 '16 at 16:04
  • 2
    @JohnHaugeland: What is “Luhn 2”? I can’t seem to find anything about it online. – lxg Mar 21 '17 at 14:14
4

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
LazyOne
  • 158,824
  • 45
  • 388
  • 391
3

The LUN check works on most credit cards. It is a modulus 10 check digit system to guarantee that the card number has been accurately read/recorded (mag stripe, virtual terminal or manual entry in the old days of the manual card imprinter).

Back in the days of manual data entry, these check systems were used to make sure that keys like UPS's pickup book numbering system were accurately entered (modulus 7 check digit).

It is even used in barcoding systems like code 128 which needs a modulus 103 digit added to the encoded data string to verify that the code was read right.

Fiasco Labs
  • 6,457
  • 3
  • 32
  • 43