Hen*_*nry 67 credit-card e-commerce
信用卡类型可以仅通过信用卡号码确定吗?
这是推荐还是总是向客户询问他们使用的信用卡类型?
我用Google搜索并找到了这个算法:http://cuinl.tripod.com/Tips/o-1.htm,这可靠吗?
谢谢
Ale*_*lex 32
是的,您提到的网站是正确的.许多网站,包括 Google Checkout我相信,依靠自动检测卡片类型.它很方便,使得UI不那么杂乱(少一个输入框)并节省时间.前进!
Lou*_*nco 21
我听说过一个很好的理由让他们选择(即使你可以搞清楚).这样他们就知道你接受的信用卡清单.
我非常肯定,至少对于万事达卡,维萨卡,发现版和美国运通卡而言,这是准确的.我从未与其他任何人合作过.
请参见本页底部:http: //www.merchantplus.com/resources/pages/credit-card-logos-and-test-numbers/
这也许对你有用" http://www.beachnet.com/~hstiles/cardtype.html
这非常有趣:http: //en.wikipedia.org/wiki/Bank_card_number
这是我使用的脚本,适用于当前的卡片范围.还会对号码进行有效性检查.
/**
* checks a given string for a valid credit card
* @returns:
* -1 invalid
* 1 mastercard
* 2 visa
* 3 amex
* 4 diners club
* 5 discover
* 6 enRoute
* 7 jcb
*/
function checkCC(val) {
String.prototype.startsWith = function (str) {
return (this.match("^" + str) == str)
}
Array.prototype.has=function(v,i){
for (var j=0;j<this.length;j++){
if (this[j]==v) return (!i ? true : j);
}
return false;
}
// get rid of all non-numbers (space etc)
val = val.replace(/[^0-9]/g, "");
// now get digits
var d = new Array();
var a = 0;
var len = 0;
var cval = val;
while (cval != 0) {
d[a] = cval%10;
cval -= d[a];
cval /= 10;
a++;
len++;
}
if (len < 13)
return -1;
var cType = -1;
// mastercard
if (val.startsWith("5")) {
if (len != 16)
return -1;
cType = 1;
} else
// visa
if (val.startsWith("4")) {
if (len != 16 && len != 13)
return -1;
cType = 2;
} else
// amex
if (val.startsWith("34") || val.startsWith("37")) {
if (len != 15)
return -1;
cType = 3;
} else
// diners
if (val.startsWith("36") || val.startsWith("38") || val.startsWith("300") || val.startsWith("301") || val.startsWith("302") || val.startsWith("303") || val.startsWith("304") || val.startsWith("305")) {
if (len != 14)
return -1;
cType = 4;
} else
// discover
if (val.startsWith("6011")) {
if (len != 15 && len != 16)
return -1;
cType = 5;
} else
// enRoute
if (val.startsWith("2014") || val.startsWith("2149")) {
if (len != 15 && len != 16)
return -1;
// any digit check
return 6;
} else
// jcb
if (val.startsWith("3")) {
if (len != 16)
return -1;
cType = 7;
} else
// jcb
if (val.startsWith("2131") || val.startsWith("1800")) {
if (len != 15)
return -1;
cType = 7;
} else
return - 1;
// invalid cc company
// lets do some calculation
var sum = 0;
var i;
for (i = 1; i < len; i += 2) {
var s = d[i] * 2;
sum += s % 10;
sum += (s - s%10) /10;
}
for (i = 0; i < len; i += 2)
sum += d[i];
// musst be %10
if (sum%10 != 0)
return - 1;
return cType;
}
Run Code Online (Sandbox Code Playgroud)