Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 704
Ahmed Nuaman Avatar asked Sep 01 '11 11:09

Ahmed Nuaman


People also ask

Is credit card number string or int?

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.

What data type is credit card number?

Credit card numbers are numeric data that follow the 14-digit or 16-digit patterns for credit cards.

What is the numeric code on a credit card?

The CSC is typically printed on the back of a credit card (usually in the signature field). On some cards, all or part of the card number appears before the CSC, for example, 1234 567. In this example, 1234 are the last four digits of the credit card number, and 567 is the CSC.

Is credit card number same as debit card number?

Is the debit or credit card account number the same as the card number? No. The entire 16-digit numeric sequence on the front of the card is the card number.


5 Answers

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
like image 179
Layke Avatar answered Sep 28 '22 09:09

Layke


Don't use an integer for this.

Depending on the size of your integers (language/machine dependent), they may be too large to store as integers.

The use of credit card numbers is also not as integers, as there's no reason for doing arithmetic with them.

You should generally regard them as arrays of decimal digits, which might most easily be stored as strings, but might merit an actual array, again depending on your programming language.

They also contain encoded banking authority information as described in the wikipedia article on Bank Card Numbers, and are a special case of ISO/IEC 7812 numbers, which in fact can start with zero (though I don't think any credit cards do). If you need this information, a CC number might actually merit it's own data type, and likely some banks implement one.

like image 29
Don Roby Avatar answered Sep 28 '22 10:09

Don Roby


Better to use an array of single-digit ints. Often the individual digits are used in some type of checksum to validate the credit card number. It would also take care of the case that a CC# actually starts with 0.

For example,

int[] cc = { 4, 3, 2, 1 }
bool Validate(int[] cc)
{
   return ((cc[0] + 2*cc[1] + 6*cc[2]) % 5) == 0;
}

Something like that, although the equations they use are more complex. This would be a lot harder (i.e. would require division and truncation) with just

int cc = 4321;


Edit:
Keep in mind also, that each digit in a credit card number means something. For example, the 3rd and 4th digits might represent the state in which the card was made, and the 5th digit might be an index to the particular bank that issued the card, for example.

like image 26
user807566 Avatar answered Sep 28 '22 09:09

user807566


Personally, I always store them as a string... it is a series of integers, much like a telephone number, not one big integer itself.

like image 45
tommy5dollar Avatar answered Sep 28 '22 10:09

tommy5dollar


I would imagine that they are integers as they (almost certainly) do not contain any alphabetic characters and never have any decimal places.

like image 43
Mus Avatar answered Sep 28 '22 11:09

Mus