Determine the type of credit card by number?

Is it possible to determine the type of credit card solely by credit card number?

Is this recommended, or should we always ask the client about the type of credit card they use?

I googled about it and found this algorithm: http://cuinl.tripod.com/Tips/o-1.htm , is it reliable?

+67
e-commerce credit-card
Aug 20 '09 at 19:03
source share
15 answers

Yes, the site you mentioned is correct. Many sites, including Google Checkout I believe I rely on automatic map type detection. This is convenient, makes the UI less cluttered (one less input field) and saves time. Move on!

+32
Aug 20 '09 at 19:04
source share

I heard one good reason to get them to choose (although you can figure it out). So that they know the list of credit cards that you accept.

+21
Aug 20 '09 at 19:07
source share

As a consumer, I hate choosing a card first. I want to just start entering the number.

This issue is discussed in Wroblewski Web Design Forms on pages 153-154. This is in the "Removing Questions" section of the "Unnecessary Entries" chapter. The above example is Paypal, which indicates the type of card when you entered your number.

+11
Aug 20 '09 at 19:25
source share

I am pretty sure that at least for MasterCard, Visa, Discover, and American Express for sure. I have never worked with anyone else.

Look at the very bottom of this page: http://www.merchantplus.com/resources/pages/credit-card-logos-and-test-numbers/

It may also be useful to you. " Http://www.beachnet.com/~hstiles/cardtype.html

This is pretty interesting: http://en.wikipedia.org/wiki/Bank_card_number

+7
Aug 20 '09 at 19:07
source share

here is the script I'm using that works with current map ranges. also checks the authenticity of the number.

/** * checks a given string for a valid credit card * @returns: * -1 invalid * 1 mastercard * 2 visa * 3 amex * 4 diners club * 5 discover * 6 enRoute * 7 jcb */ function checkCC(val) { String.prototype.startsWith = function (str) { return (this.match("^" + str) == str) } Array.prototype.has=function(v,i){ for (var j=0;j<this.length;j++){ if (this[j]==v) return (!i ? true : j); } return false; } // get rid of all non-numbers (space etc) val = val.replace(/[^0-9]/g, ""); // now get digits var d = new Array(); var a = 0; var len = 0; var cval = val; while (cval != 0) { d[a] = cval%10; cval -= d[a]; cval /= 10; a++; len++; } if (len < 13) return -1; var cType = -1; // mastercard if (val.startsWith("5")) { if (len != 16) return -1; cType = 1; } else // visa if (val.startsWith("4")) { if (len != 16 && len != 13) return -1; cType = 2; } else // amex if (val.startsWith("34") || val.startsWith("37")) { if (len != 15) return -1; cType = 3; } else // diners if (val.startsWith("36") || val.startsWith("38") || val.startsWith("300") || val.startsWith("301") || val.startsWith("302") || val.startsWith("303") || val.startsWith("304") || val.startsWith("305")) { if (len != 14) return -1; cType = 4; } else // discover if (val.startsWith("6011")) { if (len != 15 && len != 16) return -1; cType = 5; } else // enRoute if (val.startsWith("2014") || val.startsWith("2149")) { if (len != 15 && len != 16) return -1; // any digit check return 6; } else // jcb if (val.startsWith("3")) { if (len != 16) return -1; cType = 7; } else // jcb if (val.startsWith("2131") || val.startsWith("1800")) { if (len != 15) return -1; cType = 7; } else return - 1; // invalid cc company // lets do some calculation var sum = 0; var i; for (i = 1; i < len; i += 2) { var s = d[i] * 2; sum += s % 10; sum += (s - s%10) /10; } for (i = 0; i < len; i += 2) sum += d[i]; // musst be %10 if (sum%10 != 0) return - 1; return cType; } 
+5
Aug 20 '09 at 19:10
source share

Here Complete C # or VB code for all kinds of CC related things on codeproject.

  • IsValidNumber
  • GetCardTypeFromNumber
  • GetCardTestNumber
  • PassesLuhnTest

This article has been for several years without negative comments.

+5
Nov 22 '09 at 23:19
source share

Wikipedia contains a list of most map prefixes. Some cards are missing from the link you provided. It also appears that the link you provided is valid.

One of the reasons for requesting a card type is for additional verification, compare what the user has provided against the number.

+4
Aug 20 '09 at 19:13
source share

This is the php version of the same algorithm mentioned in the 1st post

 <?php function CreditCardType($CardNo) { /* '*CARD TYPES *PREFIX *WIDTH 'American Express 34, 37 15 'Diners Club 300 to 305, 36 14 'Carte Blanche 38 14 'Discover 6011 16 'EnRoute 2014, 2149 15 'JCB 3 16 'JCB 2131, 1800 15 'Master Card 51 to 55 16 'Visa 4 13, 16 */ //Just in case nothing is found $CreditCardType = "Unknown"; //Remove all spaces and dashes from the passed string $CardNo = str_replace("-", "",str_replace(" ", "",$CardNo)); //Check that the minimum length of the string isn't less //than fourteen characters and -is- numeric If(strlen($CardNo) < 14 || !is_numeric($CardNo)) return false; //Check the first two digits first switch(substr($CardNo,0, 2)) { Case 34: Case 37: $CreditCardType = "American Express"; break; Case 36: $CreditCardType = "Diners Club"; break; Case 38: $CreditCardType = "Carte Blanche"; break; Case 51: Case 52: Case 53: Case 54: Case 55: $CreditCardType = "Master Card"; break; } //None of the above - so check the if($CreditCardType == "Unknown") { //first four digits collectively switch(substr($CardNo,0, 4)) { Case 2014:Case 2149: $CreditCardType = "EnRoute"; break; Case 2131:Case 1800: $CreditCardType = "JCB"; break; Case 6011: $CreditCardType = "Discover"; break; } } //None of the above - so check the if($CreditCardType == "Unknown") { //first three digits collectively if(substr($CardNo,0, 3) >= 300 && substr($CardNo,0, 3) <= 305) { $CreditCardType = "American Diners Club"; } } //None of the above - if($CreditCardType == "Unknown") { //So simply check the first digit switch(substr($CardNo,0, 1)) { Case 3: $CreditCardType = "JCB"; break; Case 4: $CreditCardType = "Visa"; break; } } return $CreditCardType; } ?> 
+3
Oct 14 '11 at 12:12
source share

The code you provided has a partial BIN / range for Discover, omits Diner club (which is now owned by Discover), lists the types of cards that no longer exist, and they need to be added to other types (enRoute, Carte Blanche), and ignore the increasingly important basket type Maestro International.

As @Alex confirmed, you can determine the type of card from the BIN number, and many companies do it, but doing it consistently and correctly is not trivial: card brands are constantly changing, and tracking things becomes more difficult, because you try to process regional debit cards (Laser in Ireland, Maestro in Europe, etc.). I did not find the free and supported (correct) part of the code or algorithm for this anywhere.

As @MitMaro is built, Wikipedia contains a list of high-level card identifiers , as well as a more specific list of BIN numbers and ranges , which is a good start, and as gbjbaanb commented, Barclays has a publicly published list (but apparently it doesn't include Discover for any reason - apparently they are not processed on the Discover network?)

Anyway, the correct algorithm / method / function of identifying the card does the maintenance work, so if your detection program is not critical / informational (for example, the @Simon_Weaver sentence), OR you are going to enter the work to keep it up to date, I I would recommend that you skip automatic detection.

+3
Jul 09 '12 at 12:15
source share

Here is a quick dirty way to automatically determine the type of card and show it to the user as you type.

This means a) the user should not select it and b) they will not spend time looking for a drop-down list that does not exist.

A very simple version of jQuery for Amex, Visa and Mastercard. if you need other types of cards, you can take

  $('[id$=CreditCardNumber]').assertOne().keyup(function(){ // rules taken from http://en.wikipedia.org/wiki/Credit_card_number#cite_note-GenCardFeatures-0 var value = $(this).val(); $('#ccCardType').removeClass("unknown"); if ((/^4/).test(value)) { $('#ccCardType').html("Visa"); return; } if ((/^5[1-5]/).test(value)) { $('#ccCardType').html("Mastercard"); return; } if ((/^3[47]/).test(value)) { $('#ccCardType').html("Mastercard"); return; } $('#ccCardType').html("Enter card number above"); $('#ccCardType').addClass("unknown"); }); 

This is jQuery to accompany this (ASP.NET MVC):

  Card number: <%= Html.TextBox("PaymentDetails.CreditCardDetails.CreditCardNumber")%> Card Type: <span id="ccCardType" class="unknown">Enter card number above</span> 

I have a css rule for .unknown to display text in gray.

+2
Oct 24 '09 at 5:20
source share

Stripe provided this fantastic javascript library for map map detection. Let me add some code snippets and show you how to use it.

First include it on your webpage as

 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.2.3/jquery.payment.js " ></script> 

Secondly, use the cardType function to determine the map layout.

 $(document).ready(function() { var type = $.payment.cardType("4242 4242 4242 4242"); //test card number console.log(type); }); 

Here are links for links to examples and demos.

+2
Apr 17 '15 at 5:09
source share

This Python implementation should work for AmEx, Discover, Master Card, Visa:

 def cardType(number): number = str(number) cardtype = "Invalid" if len(number) == 15: if number[:2] == "34" or number[:2] == "37": cardtype = "American Express" if len(number) == 13: if number[:1] == "4": cardtype = "Visa" if len(number) == 16: if number[:4] == "6011": cardtype = "Discover" if int(number[:2]) >= 51 and int(number[:2]) <= 55: cardtype = "Master Card" if number[:1] == "4": cardtype = "Visa" return cardtype 
+1
Aug 20 '09 at 19:46
source share

If all the credit cards you have accepted have the same properties, then simply enter the card number and other properties (expiration date, CVV, etc.) to the user. However, for some types of cards, different input fields are required (for example, the start date or issue number for Maestro UK cards). In these cases, you should have all the fields, thereby confusing the user or some Javascript in order to hide / show the corresponding fields, again creating a little strange for the user (the fields disappear / appear when they enter the credit card number), In such cases, I recommend first ask for the type of card.

+1
Sep 13 '09 at 7:41
source share

Personally, I have no problem with the first choice of card type. But there are two aspects to entering a credit card number, which, in my opinion, are problematic.

Worst of all is the inability to enter spaces between groups of numbers. Including spaces printed on physical cards will make numbers much easier for users to scan to make sure they enter the information correctly. Every time I come across this ubiquitous flaw, I feel like I'm being promoted back to the Stone Age, when user input cannot be filtered to remove unnecessary characters.

The second need when placing a phone order to listen to the seller is to repeat the card number back to you. All credit card recipients really need an interface that gives them access to the check digit scheme, which verifies that the cc number is valid. According to this algorithm, the first 15 (or as many as you like) digits calculate the last digit - and itโ€™s almost impossible to โ€œtrickโ€ it. A full finger number for a โ€œpassโ€ requires at least two mutually annoying errors among 15 digits. If the algorithm does not suffer from the disadvantage that it is unfairly tricked by transferring neighboring numbers (general input error), which I doubt, I exclude that it is more reliable than any double human check.

+1
Oct 04 '14 at 18:49
source share

https://binlist.net/ offers a free API. You only need to enter the first 6 or 8 digits of the card number - that is, the issuer identification numbers (IIN), previously known as the bank identification number (BIN).

curl -H "Accept-Version: 3" "https://lookup.binlist.net/45717360"

(cross-answer to a more specific question: how to determine the difference between a debit and a credit card )

0
Feb 09 '19 at 7:40
source share



All Articles