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

别来无恙 提交于 2019-11-30 00:36:25

问题


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.


回答1:


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



回答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:

  • VISA debit / credit
  • VISA Electron
  • VISA Delta
  • MasterCard
  • AMEX
  • Maestro
  • Switch
  • Solo
  • Diners Club
  • Discover
  • JCB



回答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.



来源:https://stackoverflow.com/questions/7863058/does-the-luhn-algorithm-work-for-all-mainstream-credit-cards-discover-visa-m

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!