I'm trying to figure out how to detect the type of credit card based purely on its number. Does anyone know of a definitive, reliable way to find this?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- Space complexity of validation of a binary search
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Should client-server code be written in one “proje
- Algorithm for maximizing coverage of rectangular a
- Is there an existing solution for these particular
- How to measure complexity of a string?
The first numbers of the credit card can be used to approximate the vendor:
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
Secondly use the function cardType for detecting the card scheme.
Here are the reference links for more examples and demos.
I use https://github.com/bendrucker/creditcards-types/ to detect the credit card type from number. One issue I ran into is discover test number 6011 1111 1111 1117
from https://www.cybersource.com/developers/other_resources/quick_references/test_cc_numbers/ we can see it is a discover number because it starts by 6011. But the result I get from the creditcards-types is "Maestro". I opened the issue to the author. He replied me very soon and provide this pdf doc https://www.discovernetwork.com/downloads/IPP_VAR_Compliance.pdf From the doc we can see clearly that 6011 1111 1111 1117 does not fall into the range of discover credit card.
My solution with jQuery:
In case 0 is returned, credit card type is undetected.
"creditcard" class should be added to the credit card input field.
The regular expression rules that match the respective card vendors:
(4\d{12}(?:\d{3})?)
for VISA.(5[1-5]\d{14})
for MasterCard.(3[47]\d{13})
for AMEX.((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)
for Maestro.(3(?:0[0-5]|[68][0-9])[0-9]{11})
for Diners Club.(6(?:011|5[0-9]{2})[0-9]{12})
for Discover.(35[2-8][89]\d\d\d{10})
for JCB.