问题
I'm trying to implement recognition of a valid credit card number so that I can transition to the next field. Given that credit card numbers come in various lengths, my question is whether I can count on the fact that if I confirm a valid credit card number (via regex and Luhn algorithm use), I won't be ruling out other valid credit card numbers (in terms of both regex/Luhn AND issuance) of greater length.
回答1:
Consider Visa where valid PAN lengths are 16 to 19 digits, as the last digit is a check digit for the previous digits there will always be another PAN with an extra digit that will pass the LUHN test.
4929847243031832
49298472430318328
492984724303183283
回答2:
I am not sure if using regex is a valid way to check the validity of a credit card. It is almost absolute to say card.length=16 as any number 1234567...16 is valid I think if you are implementing a payment system to use a valid payment processing library and as such you are able to validate a credit card number via their library
回答3:
Valid credit card number(PAN - primary account number) has 11 to 24 digits , different systems have own length, plus LRC(Longitudinal redundancy check) in the end. And if it 18 symbols for VISA or mastercard, then 123456789123456789 will be valid. https://en.wikipedia.org/wiki/Longitudinal_redundancy_check It is defined in standard ISO/IEC_7813 https://en.wikipedia.org/wiki/ISO/IEC_7813
回答4:
Consider the legal issue: a user should really be the one telling you when they believe they have entered the right number. I only ever remove whitespace, anything else potentially makes you liable by interference. I would advise against what you are trying to do. At the point the user is trying to transact that type of usability isn't going to influence the transaction.
来源:https://stackoverflow.com/questions/37352477/are-there-any-valid-credit-numbers-that-are-initial-substrings-of-other-valid-cr