Search code examples
numbersintegercredit-card

Is a credit/debit card number numeric or an integer?


Since a number can also be a decimal this makes me think that a CC number should be an integer. This would make sense as I don't think any credit cards start with 0 and since they all follow the same sort of pattern:

4444333322221111

So I guess they're an integer but I'm not too sure what international cards are like? Do any start with 0?

Update

Thanks for all your responses. It's less to store them (in fact I'd only store the last 4 numbers) and more to do a quick validation check. Regardless, I'd just treat it as an integer for validation, i.e. making sure that it's between 13-16 digits in length and always never a decimal.


Solution

  • Credit card numbers are not strictly numbers. They are strings, but the numbers which make up the long 16 digit number can be exploded in order to validate the number by using the checksum of the number.

    You aren't going to be doing any multiplication or division on the CC number, so it should be a string in my opinion.

    Quick Prefix, Length, and Check Digit Criteria

    CARD TYPE      |    Prefix  |   Length  | Check digit algorithm
    -----------------------------------------------------------------
    MASTERCARD     |    51-55   |   16      |    mod 10
    VISA           |    4       |   13,  16 |    mod 10
    AMEX           |    34/37   |   15      |    mod 10
    Discover       |    6011    |   16      |    mod 10
    enRoute        | 2014/2149  |   15      |    any
    JCB            |     3      |   16      |    mod 10
    JCB            |  2131/1800 |   15      |    mod 10