Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Credit Card Numbers contain leading zeros? [closed]

Often I have stored credit card numbers in varchar(16). That works, but it takes 17 bytes per number.

Storage is not that big a deal, but I like to be efficient, for both storage requirement, and table search time.

If I could use decimal(16) unsigned, I could cut the storage requirement to 7 or 8 bytes, and still preserve readability as well as much of the compatibility.

This would strip leading zeros. Can I depend on all credit card numbers starting with a non-zero number?

like image 262
700 Software Avatar asked Aug 23 '11 17:08

700 Software


2 Answers

Credit card numbers (like phone numbers and postal codes) are not numeric and should never be stored in a numeric datatype. They are inherently string data. Numbers that are not intended to be used in mathematical calculations (except autoassigned integers that are used as ids) are string data, they will be used as string data, they will be queried as string data.

like image 180
HLGEM Avatar answered Sep 21 '22 05:09

HLGEM


According to Wikipedia, the first digit can indeed be 0:

The first digit of a credit card number is the Major Industry Identifier (MII), which represents the category of entity which issued the credit card. Different MII digits represent the following issuer categories:

  • 0 – ISO/TC 68 and other future industry assignments
  • etc.

So no, I don't think you'd want to use storage that omits leading zeros.

like image 36
Tim Jones Avatar answered Sep 23 '22 05:09

Tim Jones