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

后端 未结 3 1094
生来不讨喜
生来不讨喜 2021-01-03 23:12

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

3条回答
  •  春和景丽
    2021-01-03 23:34

    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

提交回复
热议问题