Credit Card Verification

How to check a credit card. I need to do a luhn check. Is there any api in blackberry for this?

+6
source share
1 answer

You can use the following method to check your credit card number

// ------------------- // Perform Luhn check // ------------------- public static boolean isCreditCardValid(String cardNumber) { String digitsOnly = getDigitsOnly(cardNumber); int sum = 0; int digit = 0; int addend = 0; boolean timesTwo = false; for (int i = digitsOnly.length() - 1; i >= 0; i--) { digit = Integer.parseInt(digitsOnly.substring(i, i + 1)); if (timesTwo) { addend = digit * 2; if (addend > 9) { addend -= 9; } } else { addend = digit; } sum += addend; timesTwo = !timesTwo; } int modulus = sum % 10; return modulus == 0; } 
+11
source

Source: https://habr.com/ru/post/906202/


All Articles