问题描述
我想弄清楚如何检测其数量完全根据信用卡的类型。有谁知道一个明确的,可靠的方法来找到这个?
的信用卡/借记卡号码被称为 PAN 或主帐号的。银行识别 - 潘的前六位从 IIN 或发卡行识别号的,属于开证行(不结盟研究所为previously称为BIN拍摄数字 - 所以你可能会看到某些文档中提及的术语)。这些六位受国际标准, ISO / IEC 7812 的,并且可以被用来确定的类型机卡分离数字。
不幸的是,实际的ISO / IEC 7812数据库是不公开的,但也有非官方的名单,包括商业和自由,包括维基百科。
总之,检测从数量型,你可以使用常规的EX pression类似下面的:
签证: ^ 4 [0-9] {6} $
的Visa卡号码开始与4
万事达: ^ 5 [1-5] [0-9] {5} $
万事达号开始通过数字51 55,但这只会检测万事达信用卡;有使用万事达卡系统不属于这一IIN范围内发行的其他卡。
美国前preSS: ^ 3 [47] [0-9] {5} $
美国前preSS卡号开始与34或37。
大莱卡: ^ 3(?:0 [0-5] | [68] [0-9])[0-9] {4} $
大来卡的卡号开头的300至305,36或38有大莱卡卡开始5,并有16位。这些都是大莱卡和万事达的合资企业,而应该像万事达被处理。
查看: ^ 6(?:011 | 5 [0-9] {2})[0-9] {3,} $
查看卡号开头6011或65。
JCB: ^(?:2131 | 1800 | 35 [0-9] {3})[0-9] {3,} $
JCB卡开始2131,1800或35。
不幸的是有许多与万事达卡系统不生活在万事达卡的IIN范围内处理卡类型(数字首发51 ... 55);最重要的例子是,大师卡,其中很多已发出来自其他银行的IIN范围,因此也遍布号空间。其结果是,这可能是最好的假设任何卡是某些其他类型您接受必须是万事达卡的不
重要:卡号就长短不一;例如,维萨公司在过去13个数字盘和卡16位的PAN发行的信用卡。 Visa的文档现在表明,它可以发出或已与12 19之间的数字发行数量。 所以,你不应该检查卡号的长度,除了要验证它至少有7个数字(一个完整的IIN加上一个校验位,这应与pdicted价值$ P $通过的卢恩算法)。
一名提示:处理持卡人出锅前,剥去任何空格和标点字符的输入。为什么?因为它是典型的多的更容易进入的分组数字,类似于他们是如何在前面一个实际的信用卡,即
显示 4444 4444 4444 4444
更易于正确地输入比
4444444444444444
这确实在鞭挞的用户,因为他们已经进入了,你不要指望在这里的字符没有好处。
这也意味着确保您的项目领域有空间的至少的24个字符,谁进入空间将运行的空间,否则用户。我建议你做的领域足够宽,可显示32个字符,并允许多达64个; ,让大量的空间进行扩展。
下面是一个形象,让更多一点的见解:
更新(2014年):的校验方法似乎不再是核实卡的真实性的有效方法作为对这个答案的评论指出,
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?
The credit/debit card number is referred to as a PAN, or Primary Account Number. The first six digits of the PAN are taken from the IIN, or Issuer Identification Number, belonging to the issuing bank (IINs were previously known as BIN — Bank Identification Numbers — so you may see references to that terminology in some documents). These six digits are subject to an international standard, ISO/IEC 7812, and can be used to determine the type of card from the number.
Unfortunately the actual ISO/IEC 7812 database is not publicly available, however there are unofficial lists, both commercial and free, including on Wikipedia.
Anyway, to detect the type from the number, you can use a regular expression like the ones below: Credit for original expressions
Visa: ^4[0-9]{6,}$
Visa card numbers start with a 4.
MasterCard: ^5[1-5][0-9]{5,}$
MasterCard numbers start with the numbers 51 through 55, but this will only detect MasterCard credit cards; there are other cards issued using the MasterCard system that do not fall into this IIN range.
American Express: ^3[47][0-9]{5,}$
American Express card numbers start with 34 or 37.
Diners Club: ^3(?:0[0-5]|[68][0-9])[0-9]{4,}$
Diners Club card numbers begin with 300 through 305, 36 or 38. There are Diners Club cards that begin with 5 and have 16 digits. These are 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,}$
Discover card numbers begin with 6011 or 65.
JCB: ^(?:2131|1800|35[0-9]{3})[0-9]{3,}$
JCB cards begin with 2131, 1800 or 35.
Unfortunately there are a number of card types processed with the MasterCard system that do not live in MasterCard’s IIN range (numbers starting 51...55); the most important case is that of Maestro cards, many of which have been issued from other banks’ IIN ranges and so are located all over the number space. As a result, it may be best to assume that any card that is not of some other type you accept must be a MasterCard.
Important: card numbers do vary in length; for instance, Visa has in the past issued cards with 13 digit PANs and cards with 16 digit PANs. Visa’s documentation currently indicates that it may issue or may have issued numbers with between 12 and 19 digits. Therefore, you should not check the length of the card number, other than to verify that it has at least 7 digits (for a complete IIN plus one check digit, which should match the value predicted by the Luhn algorithm).
One further hint: before processing a cardholder PAN, strip any whitespace and punctuation characters from the input. Why? Because it’s typically much easier to enter the digits in groups, similar to how they’re displayed on the front of an actual credit card, i.e.
4444 4444 4444 4444
is much easier to enter correctly than
4444444444444444
There’s really no benefit in chastising the user because they’ve entered characters you don't expect here.
This also implies making sure that your entry fields have room for at least 24 characters, otherwise users who enter spaces will run out of room. I’d recommend that you make the field wide enough to display 32 characters and allow up to 64; that gives plenty of headroom for expansion.
Here's an image that gives a little more insight:
UPDATE (2014): The checksum method no longer appears to be a valid way of verifying a card's authenticity as noted in the comments on this answer.
这篇关于你如何检测基于一些信用卡类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!