您如何根据号码检测信用卡类型? [英] How do you detect Credit card type based on number?

查看:23
本文介绍了您如何根据号码检测信用卡类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何仅根据信用卡号码来检测信用卡类型.有没有人知道找到这个的确定的、可靠的方法?

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?

推荐答案

信用卡/借记卡号称为 PAN主帐号.PAN 的前六位数字取自属于发卡行的 IINIssuer Identification Number(IIN 以前称为 BIN — 银行标识号 — 所以您可能会在某些文档中看到对该术语的引用).这六位数字符合国际标准ISO/IEC 7812,可以使用从号码中判断卡的类型.

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.

遗憾的是,实际的 ISO/IEC 7812 数据库并未公开提供,但是,有一些非官方的商业和免费列表,包括 维基百科上.

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 卡号以 4 开头.

Visa: ^4[0-9]{6,}$ Visa card numbers start with a 4.

万事达卡: ^5[1-5][0-9]{5,}|222[1-9][0-9]{3,}|22[3-9][0-9]{4,}|2[3-6][0-9]{5,}|27[01][0-9]{4,}|2720[0-9]{3,}$ 2016 年之前,万事达卡号码以数字 51 到 55 开头,但这只会检测万事达信用卡;还有其他使用万事达卡系统发行的卡不属于此 IIN 范围.2016年,他们将添加范围内的数字(222100-272099).

MasterCard: ^5[1-5][0-9]{5,}|222[1-9][0-9]{3,}|22[3-9][0-9]{4,}|2[3-6][0-9]{5,}|27[01][0-9]{4,}|2720[0-9]{3,}$ Before 2016, 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. In 2016, they will add numbers in the range (222100-272099).

美国运通: ^3[47][0-9]{5,}$ 美国运通卡号以 34 或 37 开头.

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 卡号以 300 到 305、36 或 38 开头.有一些 Diners Club 卡以 5 开头并有 16 位数字.这些是大来卡和万事达卡的合资企业,应该像万事达卡一样处理.

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.

发现: ^6(?:011|5[0-9]{2})[0-9]{3,}$ 发现卡号开始6011 或 65.​​

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 卡开始2131、1800 或 35.

JCB: ^(?:2131|1800|35[0-9]{3})[0-9]{3,}$ JCB cards begin with 2131, 1800 or 35.

不幸的是,有许多由 MasterCard 系统处理的卡类型不在 MasterCard 的 IIN 范围内(数字从 51...55 开始);最重要的例子是 Maestro 卡,其中许多卡是从其他银行的 IIN 范围发行的,因此遍布整个号码空间.因此,最好假设任何不属于您接受的其他类型的卡都必须是万事达卡.

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.

重要:卡号的长度确实不同;例如,Visa 过去曾发行过带有 13 位 PAN 的卡和带有 16 位 PAN 的卡.Visa 的文件目前表明它可能发布或可能已经发布了 12 到 19 位数字的号码.因此,除了验证它至少有 7 位数字外,您不应该检查卡号的长度(对于完整的 IIN 加一个校验位,它应该与 Luhn 算法).

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).

进一步提示:在处理持卡人 PAN 之前,从输入中去除任何空格和标点符号.为什么?因为通常按组输入数字要容易得多,类似于它们在实际信用卡正面的显示方式,即

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

4444444444444444

惩罚用户真的没有任何好处,因为他们在这里输入了你不期望的字符.

There’s really no benefit in chastising the user because they’ve entered characters you don't expect here.

这也意味着确保您的输入字段有至少 24 个字符的空间,否则输入空格的用户将没有空间.我建议您这样做您使字段足够宽以显示 32 个字符并允许最多 64 个字符;这为扩展提供了充足的空间.

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:

更新(2016 年):万事达卡将实施新的 BIN 范围,从 Ach Payment 开始.

UPDATE (2016): Mastercard is to implement new BIN ranges starting Ach Payment.

这篇关于您如何根据号码检测信用卡类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆