|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.commons.validator.routines.CreditCardValidator
public class CreditCardValidator
Perform credit card validations.
By default, all supported card types are allowed. You can specify which
cards should pass validation by configuring the validation options. For
example,CreditCardValidator ccv = new CreditCardValidator(CreditCardValidator.AMEX + CreditCardValidator.VISA);
configures the validator to only pass American Express and Visa cards.
If a card type is not directly supported by this class, you can implement
the CreditCardType interface and pass an instance into the
addAllowedCardType method.
| Field Summary | |
|---|---|
static long |
AMEX
Option specifying that American Express cards are allowed. |
static CodeValidator |
AMEX_VALIDATOR
American Express (Amex) Card Validator |
private java.util.List |
cardTypes
The CreditCardTypes that are allowed to pass validation. |
static long |
DINERS
Option specifying that Diners cards are allowed. |
static CodeValidator |
DINERS_VALIDATOR
Diners Card Validator |
static long |
DISCOVER
Option specifying that Discover cards are allowed. |
private static RegexValidator |
DISCOVER_REGEX
Discover Card regular expressions |
static CodeValidator |
DISCOVER_VALIDATOR
Discover Card Validator |
private static CheckDigit |
LUHN_VALIDATOR
Luhn checkdigit validator for the card numbers. |
static long |
MASTERCARD
Option specifying that Mastercard cards are allowed. |
static CodeValidator |
MASTERCARD_VALIDATOR
Mastercard Card Validator |
static long |
NONE
Option specifying that no cards are allowed. |
static long |
VISA
Option specifying that Visa cards are allowed. |
static CodeValidator |
VISA_VALIDATOR
Visa Card Validator |
| Constructor Summary | |
|---|---|
CreditCardValidator()
Create a new CreditCardValidator with default options. |
|
CreditCardValidator(CodeValidator[] creditCardValidators)
Create a new CreditCardValidator with the specified CodeValidators. |
|
CreditCardValidator(long options)
Create a new CreditCardValidator with the specified options. |
|
| Method Summary | |
|---|---|
private boolean |
isOn(long options,
long flag)
Tests whether the given flag is on. |
boolean |
isValid(java.lang.String card)
Checks if the field is a valid credit card number. |
java.lang.Object |
validate(java.lang.String card)
Checks if the field is a valid credit card number. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long NONE
CreditCardValidator v = new CreditCardValidator(CreditCardValidator.NONE); v.addAllowedCardType(customType); v.isValid(aCardNumber);
public static final long AMEX
public static final long VISA
public static final long MASTERCARD
public static final long DISCOVER
public static final long DINERS
private final java.util.List cardTypes
private static final CheckDigit LUHN_VALIDATOR
public static final CodeValidator AMEX_VALIDATOR
public static final CodeValidator DINERS_VALIDATOR
private static final RegexValidator DISCOVER_REGEX
public static final CodeValidator DISCOVER_VALIDATOR
public static final CodeValidator MASTERCARD_VALIDATOR
public static final CodeValidator VISA_VALIDATOR
| Constructor Detail |
|---|
public CreditCardValidator()
public CreditCardValidator(long options)
options - Pass in
CreditCardValidator.VISA + CreditCardValidator.AMEX to specify that
those are the only valid card types.public CreditCardValidator(CodeValidator[] creditCardValidators)
CodeValidators.
creditCardValidators - Set of valid code validators| Method Detail |
|---|
public boolean isValid(java.lang.String card)
card - The card number to validate.
public java.lang.Object validate(java.lang.String card)
card - The card number to validate.
null
if invalid.
private boolean isOn(long options,
long flag)
options - The options specified.flag - Flag value to check.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||