从卡号识别卡类型
我有一系列的卡类型,看起来像这样
var cards = new Array();
cards [0] = {name: "VISA", length: "13,16", prefixes: "4", checkdigit: true};
cards [1] = {name: "VISA_DELTA/ELECTRON", length: "16", prefixes: "417500,4917,4913", checkdigit: true};
,但是 id 希望能够根据输入的卡号找到卡类型。例如,如果他们从下拉列表中选择卡类型(即 Visa),则信用卡号应以 4 开头,否则当他们提交表单时,应显示某种消息说明这是(无论是什么卡,请更改卡)类型)。任何帮助将不胜感激。
卡号文本字段的 ID 是 CardNumber。我不确定可能还需要什么其他信息,我有一个名为 Validate 的函数,它会验证表单的其余部分,还有一个函数调用Calculate 来进行 luhn 检查。
i have an array of card types that looks something like this
var cards = new Array();
cards [0] = {name: "VISA", length: "13,16", prefixes: "4", checkdigit: true};
cards [1] = {name: "VISA_DELTA/ELECTRON", length: "16", prefixes: "417500,4917,4913", checkdigit: true};
however id like to be able to find the card type depending on the card number entered. e.g if they select their card type from a drop down list i.e visa, then the credit card number should start with 4 otherwise when they submit the form a message of some sort should be display saying this is (whatever card it is, please change card type). Any help would be appreciated.
the id for the card number text field is CardNumber. Im not sure what other info may be needed, i have a function called Validate which validates the rest of the form and a function call Calculate which does the luhn check.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信您可能正在寻找这样的东西:
最初发布于此处@ http://mel-green.com/2008/11/define-credit-card-type-with-javascript/
I believe you are probably looking for something like this:
Originally posted here @ http://mel-green.com/2008/11/determine-credit-card-type-with-javascript/
这里有一个专门为此设计的 jQuery 插件:
http://jquerycreditcardvalidator.com/
另请参阅此 StackOverflow 答案以获得优秀的答案关于信用卡号与卡类型之间关系的讨论:
https://stackoverflow.com/a/72801/12484
Here's a jQuery plugin designed for exactly this:
http://jquerycreditcardvalidator.com/
See also this StackOverflow answer for an excellent discussion of how credit card numbers are related to card types:
https://stackoverflow.com/a/72801/12484
卡公司有一个相当明确的前缀列表,这些前缀特定于卡类型。
这些前缀的范围从单个数字(以“5”开头的都是万事达卡)到一些长达六位或七位数字的字符串,适用于更晦涩的卡类型,也适用于主流卡,但不仅能够识别卡类型还有发卡银行。
这是我找到的一个资源: http://www.beachnet.com/~hstiles/cardtype.html
您可能还想查看维基百科:http://en.wikipedia.org/wiki/Credit_card_numbers
缺点是,虽然现在流通的前缀几乎是固定的,但他们总有可能需要要提出更多,因此您需要确保所有前缀列表保持最新,特别是当您使用它来检查较长的前缀范围时。
The card companies have a fairly well-defined list of prefixes which are specific to the card type.
These prefixes range from a single digit (everything begining with '5' is Mastercard) to some strings up to six or seven digits long, for more obscure card types, and also for mainstream cards, but being able to identify not only the card type but also the issuing bank.
Here's one resource I found: http://www.beachnet.com/~hstiles/cardtype.html
You may also want to see Wikipedia: http://en.wikipedia.org/wiki/Credit_card_numbers
The down side is that while the prefixes that are in circulation now are pretty much fixed, there's always the likelyhood that they'll need to come up with more, so you would need to ensure that you keep any prefix list up-to-date, especially if you're using it to check the longer prefix ranges.
卡前缀方案在 BIN(银行 ID 号)列表中详细说明并定期更改,我建议不要验证 PAN 的完整前 6 位数字,除非您计划定期更新并且仅对前几位数字进行粗略检查(例如,您的签证/选举缺少 48*,签证长度可以跨越 16-19)。
如果您在英国; http://www.barclaycard.co.uk/business/documents/pdfs /bin_rules.pdf
The card prefix scheme is detailed in BIN (bank id number) lists and change regularly, I would advise against validating against the full 1st 6 digits of the PAN unless you plan regular updates and only perform a cursory check on the first couple of digits (your missing 48* for for visa/electon for example and visa length can span 16-19).
If your in the UK; http://www.barclaycard.co.uk/business/documents/pdfs/bin_rules.pdf