- /*
- Verification process:
- 1. Starting with the last digit of the card number, the inverse adds the odd digits (1, 3, 5, and so on).
- 2, starting from the last digit of the card number, the inverse of the even digit number, first multiplied by 2 (if the product is two digits, the bit 10 digits are added, will be minus 9), and then summed.
- 3, the sum of odd digits plus even digits sum, the result should be divisible by 10.
- */
- /**
- * Verify the bank card number
- */
- public Static boolean checkbankcard (String bankcard) {
- if (Bankcard.length () < | | bankcard.length () > ) {
- return false;
- }
- char bit = Getbankcardcheckcode (bankcard.substring (0, Bankcard.length ()- 1));
- if (bit = = ' N ') {
- return false;
- }
- return Bankcard.charat (Bankcard.length ()- 1) = = bit;
- }
- /**
- * The check digit is obtained from the bank card number without check digit using LUHM check algorithm.
- * @param noncheckcodebankcard
- * @return
- */
- public static char getbankcardcheckcode (String noncheckcodebankcard) {
- if (Noncheckcodebankcard = = Null | | Noncheckcodebankcard.trim (). Length () = = 0
- || !noncheckcodebankcard.matches ("\\d+")) {
- //If the data passed is not returned by N
- return ' N ';
- }
- char[] CHS = Noncheckcodebankcard.trim (). ToCharArray ();
- int luhmsum = 0;
- for (int i = chs.length- 1, j = 0; I >= 0; I--, j + +) {
- int k = chs[i]- ' 0 ';
- if (j% 2 = = 0) {
- K *= 2;
- K = k/ ten + k% 10;
- }
- Luhmsum + = k;
- }
- return (luhmsum% = = 0)? ' 0 ': (char) ((10-luhmsum% ) + ' 0 ');
- }
Java Inspection Bank card number