我正在制作一个检查有效卡号的自定义视图。这就是我验证卡号的方式。
boolean validateNumber(CharSequence number) {
// This is for an exception.
if(number.toString().startsWith("941082")) return true;
int sum = 0;
final int size = number.length();
final int checkDigit = number.charAt(size - 1) - '0';
boolean doubleDigit = true;
for (int index = size - 1; --index >= 0; doubleDigit = !doubleDigit) {
int digit = number.charAt(index) - '0';
if (doubleDigit) {
digit *= 2;
if (digit > 9) {
//sum the two digits together,
//the first is always 1 as the highest
// double will be 18
digit = 1 + (digit % 10);
}
}
sum += digit;
}
return ((sum + checkDigit) % 10) == 0;
}
但很少有一些牌没有通过。我该如何解决这个问题?
来源:https ://www.ksnet.co.kr/Bbs?ci=NOTICE&c=NOTICE&fi=&fw=&f=ALL&q=BIN
源提供 BIN。但是,即使在它们之后,卡也有更多的数字,并且它们有时对该功能无效。我怎样才能检查那些例外卡号?(超过3000例)
这些问题主要是在以 9 开头的国内(韩国)卡中引起的。