Determine credit card type by number?

后端 未结 15 1947
旧巷少年郎
旧巷少年郎 2020-11-30 19:44

Can credit card type be determined solely from the credit card number?

Is this recommended or should we always ask client for the type of credit card they\'re using?

相关标签:
15条回答
  • 2020-11-30 19:45

    Personally I have no problem with picking the card type first. But there are two aspects of credit card number entry that are problematic in my view.

    The worst is the inability to enter spaces between groups of numbers. Including the spaces printed on the physical cards would make the digits vastly easier for the user to scan to verify they've entered the information correctly. Every time I encounter this ubiquitous deficiency I feel like I'm being propelled backwards into a stone age when user input couldn't be filtered to remove unnecessary characters.

    The second is the need when placing a phone order to listen to the vendor repeat the card number back to you. All the credit card recipient actually needs is a UI that gives them access to the check digit scheme which verifies that a cc number is valid. According to that algorithm the first 15 (or however many) digits calculate the last digit - and is virtually impossible to "fool." For a fat fingered number to "pass" requires at least two mutually canceling errors among the 15 digits. Unless the algorithm suffers from the defect of being dis-proportionally fooled by transposing adjacent numbers (a common entry error) which I doubt, I except it is more reliable than any human double check.

    0 讨论(0)
  • 2020-11-30 19:47

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

    • IsValidNumber
    • GetCardTypeFromNumber
    • GetCardTestNumber
    • PassesLuhnTest

    This article has been up for a couple years with no negative comments.

    0 讨论(0)
  • 2020-11-30 19:49

    Stripe has provided this fantastic javascript library for card scheme detection. Let me add few code snippets and show you how to use it.

    Firstly Include it to your web page as

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

    Secondly use the function cardType for detecting the card scheme.

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

    Here are the reference links for more examples and demos.

    1. Stripe blog for jquery.payment.js
    2. Github repository
    0 讨论(0)
  • 2020-11-30 19:51

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

    One reason to ask for the card type is for extra validation, compare what the user provided against the number.

    0 讨论(0)
  • 2020-11-30 19:53

    Yes, the site you mentioned is correct. Many sites, incl. Google Checkout I believe, rely on automatic detection of the card type. It's convenient, makes the UI less cluttered (one less input box) and saves time. Go ahead!

    0 讨论(0)
  • 2020-11-30 19:57

    https://binlist.net/ offers a free API. You only need to enter the first 6 or 8 digits of the card number - i.e. the Issuer Identification Numbers (IIN), previously known as Bank Identification Number (BIN).

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

    • NPM: https://www.npmjs.com/package/binlookup
    • Source: https://github.com/paylike/binlookup

    (cross-posted from a more specific question: How tell the difference between a Debit Card and a Credit Card )

    0 讨论(0)
提交回复
热议问题