com.keyoti.creditCard.logic
Class LuhnChecker
java.lang.Object
|
+--com.keyoti.creditCard.logic.LuhnChecker
- public class LuhnChecker
- extends Object
Checks for validity of a credit card NUMBER using Luhn algorithm (MOD10).
Does NOT check for validity of a credit CARD. This means that this is mostly used for detecting typos and
garbage input. Of course it can't tell you if the credit card number is associated to a valid account with
money in it.
- Author:
- Keyoti
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
LuhnChecker
public LuhnChecker()
containsInvalidCharacters
public static boolean containsInvalidCharacters(String s)
- Checks if a String contains characters that are not valid in a credit card number.
Invalid characters are ANYTHING BUT digits (0-9), hyphens and whitespace.
- Parameters:
s - the credit card number to check.- Returns:
- true if there are invalid characters in the credit card number.
isValid
public static boolean isValid(String cardNumber)
- Perform Luhn & character validity check.
- Parameters:
cardNumber - String containing the card number to check.- Returns:
- true if all characters in string are valid (digits, spaces, hyphens) AND conform to Luhn check.
check
public static boolean check(String cardNumber)
- Perform Luhn check. Ignores any characters that are not digits.
- Parameters:
cardNumber - String containing the card number to check.- Returns:
- true if digits conform to Luhn check, false if not (including if string is devoid of digits)
getDigitsOnly
public static String getDigitsOnly(String s)
- Filter out non-digit characters.
- Parameters:
s - String to remove white space and hyphen chars from.
Copyright © 2002 Keyoti All Rights Reserved.