I am making a custom view that checks valid card number. This is how I validate the card number.
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;
}
But rarely, some cards aren't passed. How can I solve this issue?
source: https://www.ksnet.co.kr/Bbs?ci=NOTICE&c=NOTICE&fi=&fw=&f=ALL&q=BIN
The source provides BINs. However, even after them, card has more numbers and they are not valid somtimes with the function. How can I check those exception card numbers? (It's more than 3000 cases)
Those problems were caused mostly in Domestic(Korean) Card that starts with 9.
I`m using Kotlin Language
And Finally You using Function isValidCard
This working for me.