algorithm - How do you detect Credit card type based on number? -


I am trying to figure out how to determine the type of credit card based only on its number. Does anyone know this in a certain, reliable way to know?

Credit / debit card number one pan , or primary account As the number , the first six digits of the PAN are taken from IIN , or Issuer Identity Number , which are related to the issuing bank (IIN first BIN - known as Bank Identity Number) You can see the context of that terminology in some documents). These six digits are subject to an international standard, and it can be used to determine the type of card from the number.

Unfortunately, the actual ISO / IEC 7812 database is not available publicly, although the informal list

However, to find out the type of numbers, Like a regular expression can use:

Visa: ^ 4 [0- 9] {6,} $ Visa card number 4 begins.

MasterCard: ^ 5 [1-5] [0-9] {5,} | 222 [1-9] [0-9] {3,} | 22 [3-9] [0-9] {4,} | 2 [3 -6] [0-9] {5,} | 27 [01] [0-9] {4,} | 2720 ​​[0-9] {3,} $ before 2016, the number starts with the master card number 51 to 55, but it will only detect the master card credit card ; Other cards are issued using the MasterCard system, which does not fall under this IIN category. In 2016, they will add numbers to the category (222100-2720 99).

American Express: ^ 3 [47] [0-9] {5,} $ with American Express card number 34 or 37 begins.

Diners Club: ^ 3 (?: 0 [0-5] | [68] [0- 9]) [0- 9] {4,} $ The Diners Club card number starts with 300 to 305, 36 or 38. Diners Club starts with Card 5 and has 16 points. This is a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard.

Discover: ^ 6 (?: 011 | 5 [0-9]] {2}) [0- 9] {3,} $ Start with the number of disc cards 6011 or 65.

JCB: ^ (?: 2131 | 1800 | 35 [0-9] {3}) [0- 9] {3,} $ JCB cards begin with 2131, 1800 or 35.

Unfortunately there are no MasterCard's IIN category, the number of card types processed with MasterCard system (starting from number 51 ... 55); The most important case is of Maestro card, many of which have been issued from other banks' IIN Range and they are located at all the numbers. As a result, It may be best to believe that the card you accept is not of any other type, it should be a MasterCard .

Important : Card number varies in length; For example, Visa has issued 13-digit pens and 16-digit pens cards in the past. At present, documents of the visa indicate that they can issue with or issue 12 to 19 points. Therefore, you should not check the length of the card number besides verifying that it has at least 7 digits (for a full IIN and a check digit, which is the predicted value Should match).

Another sign: Before processing a card holder pan, press any white space and punctuation marks from the input Why do not you? Since it is usually easy to enter digits in too many groups, in the same way they are displayed in front of the actual credit card, i.e.

  4444 4444 4444 4444 < It is very easy to login correctly with / code>  

4444444444444444

There is no benefit in punishing the user because they You do not expect that here.

Also ensures that the entry field is at least for 24 characters, otherwise the users who enter the spaces will exit the room. . I recommend making the field enough to show you 32 characters and allow up to 64;

UPDATE (2014): Checksum Method

UPDATE (2016): MasterCard is new to implement There is no valid way to verify the authenticity of this card .

credit card verification


Comments

Popular posts from this blog

sockets - Delphi: TTcpServer, connection reset when reading -

kernel - How to create a "Block device" in Windows -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -