3

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.

3
  • I see a tumbleweed badge in your near future
    – John Conde
    May 21, 2016 at 13:09
  • What does this have to do with programming, though?
    – doug65536
    May 29, 2016 at 18:34
  • It concerns the programming matter of whether you can reasonably auto advance on the last digit of credit card number entry. I admit, though, that it's fundamentally not a programming matter. May 29, 2016 at 18:37

4 Answers 4

3
+50

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
6
  • I was thinking that perhaps Visa wouldn't issue, by policy, any numbers where the immediately previous substring was valid. That still leaves them plenty of expansion. Are you sure that's not the case? May 21, 2016 at 13:55
  • I don't know what their policy is regarding this.
    – Alex K.
    May 21, 2016 at 15:16
  • 1
    @Peter. Visa don't directly manage each and every number. They allocate ranges to issuers. The first six digits are the issuer identifier number, the remaining digits are allocated by that issuer. Whether Visa provides guidance on the scenario as suggested here, I'm not sure. My suspicion though would be that even if they did, you'd probably find one quirky issuer that ignored that guidance.
    – PaulG
    May 23, 2016 at 14:28
  • @PaulG If you want to put this into an answer, the bounty is yours, as this seems to be the most information I'm going to get. :-) May 28, 2016 at 20:54
  • @PeterAlfvin, perhaps Alex can edit this information into his answer. I'd still say this answer is fundamentally correct for your problem. I did spend some time scanning through some official Visa docs and didn't see anything that would mitigate this issue.
    – PaulG
    May 29, 2016 at 8:01
0

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
  • I said regex and Luhn test. See referenced question for details. Going to the server is not practical for each character typed. May 21, 2016 at 13:57
  • just a simple google of luhn and credit card gives me this rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#C.23 and it looks pretty simple to implement. Have you seen it? I was referring to when you are implementing a third party payment library and need a custom validation.
    – Jack M
    May 21, 2016 at 20:17
  • As I pointed out in my comment on the other answer, this is not a question of code or even the Luhn algorithm, for which I already have a perfectly fine working implementation. This is a question about credit card issuance policy. May 21, 2016 at 21:17
0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.