|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.behavior.Behavior org.apache.wicket.validation.validator.AbstractValidator<String> org.apache.wicket.validation.validator.CreditCardValidator
public class CreditCardValidator
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.
Nested Class Summary | |
---|---|
static class |
CreditCardValidator.CreditCard
|
Constructor Summary | |
---|---|
CreditCardValidator()
Construct. |
|
CreditCardValidator(boolean failOnUnkown)
Construct. |
Method Summary | |
---|---|
CreditCardValidator.CreditCard |
determineCardId(String creditCardNumber)
Checks if the credit card number can be determined as a valid number. |
CreditCardValidator.CreditCard |
getCardId()
|
protected 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 |
isUnknown(String creditCardNumber)
Can be used (subclassed) to extend the test with a credit card not yet known by the validator. |
protected void |
onValidate(IValidatable<String> validatable)
Validates the IValidatable instance. |
protected void |
setCardId(CreditCardValidator.CreditCard cardId)
Allow subclasses to set the card id |
Methods inherited from class org.apache.wicket.validation.validator.AbstractValidator |
---|
error, error, error, error, resourceKey, validate, validateOnNullValue, variablesMap |
Methods inherited from class org.apache.wicket.behavior.Behavior |
---|
afterRender, beforeRender, bind, canCallListenerInterface, canCallListenerInterface, detach, getStatelessHint, isEnabled, isTemporary, onComponentTag, onConfigure, onEvent, onException, renderHead, unbind |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CreditCardValidator()
public CreditCardValidator(boolean failOnUnkown)
failOnUnkown
- Method Detail |
---|
public final CreditCardValidator.CreditCard getCardId()
protected void setCardId(CreditCardValidator.CreditCard cardId)
cardId
- protected void onValidate(IValidatable<String> validatable)
IValidatable
instance.
onValidate
in class AbstractValidator<String>
validatable
- the given IValidatable
instanceprotected boolean isLengthAndPrefixCorrect(String creditCardNumber)
creditCardNumber
- the credit card number as a string
TRUE
if the credit card number could be determined as a valid number,
else FALSE
is returnedpublic final CreditCardValidator.CreditCard determineCardId(String creditCardNumber)
creditCardNumber
- the credit card number as a string
TRUE
if the credit card number could be determined as a valid number,
else FALSE
is returnedprotected CreditCardValidator.CreditCard isUnknown(String creditCardNumber)
creditCardNumber
- the credit card number as a string
protected final boolean isChecksumCorrect(String creditCardNumber)
creditCardNumber
- the credit card number for which the checksum should be calculated
TRUE
if the checksum for the given credit card number is valid, else
return FALSE
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |