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

后端 未结 3 1081
生来不讨喜
生来不讨喜 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
    0 讨论(0)
  • 2021-01-03 23:36

    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.

    0 讨论(0)
  • 2021-01-03 23:38

    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
    0 讨论(0)
提交回复
热议问题