Module org.apache.wicket.core
Class CreditCardValidator
java.lang.Object
org.apache.wicket.validation.validator.CreditCardValidator
- All Implemented Interfaces:
Serializable
,IClusterable
,IValidator<String>
Checks if a credit card number is valid. The number will be checked for "American Express",
"China UnionPay", "Diners Club Carte Blanche", "Diners Club International",
"Diners Club US & Canada", "Discover Card", "JCB", "Laser", "Maestro", "MasterCard", "Solo",
"Switch", "Visa" and "Visa Electron". If none of those apply to the credit card number, the
credit card number is considered invalid.
Card prefixes and lengths have been taken from Wikipedia.
- Since:
- 1.2.6
- Author:
- Johan Compagner, Joachim F. Rohde
- See Also:
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected IValidationError
decorate
(IValidationError error, IValidatable<String> validatable) Allows subclasses to decorate reported errorsdetermineCardId
(String creditCardNumber) Checks if the credit card number can be determined as a valid number.protected final boolean
isChecksumCorrect
(String creditCardNumber) Calculates the checksum of a credit card number using the Luhn algorithm (the so-called "mod 10" algorithm).protected boolean
isLengthAndPrefixCorrect
(String creditCardNumber) Checks if the credit card number can be determined as a valid number.protected CreditCardValidator.CreditCard
Can be used (subclassed) to extend the test with a credit card not yet known by the validator.protected void
Allow subclasses to set the card idvoid
validate
(IValidatable<String> validatable) Validates theIValidatable
instance.
-
Constructor Details
-
CreditCardValidator
public CreditCardValidator()Construct. -
CreditCardValidator
Construct.- Parameters:
failOnUnknown
-
-
-
Method Details
-
getCardId
- Returns:
- Credit card issuer
-
setCardId
Allow subclasses to set the card id- Parameters:
cardId
-
-
validate
Description copied from interface:IValidator
Validates theIValidatable
instance. Validation errors should be reported using theIValidatable.error(IValidationError)
method.- Specified by:
validate
in interfaceIValidator<String>
- Parameters:
validatable
- theIValidatable
instance being validated
-
decorate
Allows subclasses to decorate reported errors- Parameters:
error
-validatable
-- Returns:
- decorated error
-
isLengthAndPrefixCorrect
Checks if the credit card number can be determined as a valid number.- Parameters:
creditCardNumber
- the credit card number as a string- Returns:
TRUE
if the credit card number could be determined as a valid number, elseFALSE
is returned
-
determineCardId
Checks if the credit card number can be determined as a valid number.- Parameters:
creditCardNumber
- the credit card number as a string- Returns:
TRUE
if the credit card number could be determined as a valid number, elseFALSE
is returned
-
isUnknown
Can be used (subclassed) to extend the test with a credit card not yet known by the validator.- Parameters:
creditCardNumber
- the credit card number as a string- Returns:
- The credit card id of the issuer
-
isChecksumCorrect
Calculates the checksum of a credit card number using the Luhn algorithm (the so-called "mod 10" algorithm).- Parameters:
creditCardNumber
- the credit card number for which the checksum should be calculated- Returns:
TRUE
if the checksum for the given credit card number is valid, else returnFALSE
- See Also:
-