public class CreditCardTypeConverter extends java.lang.Object implements TypeConverter<java.lang.String>
A faux TypeConverter that validates that the String supplied is a valid credit card number. The Luhn algorithm is used in addition to valid credit card prefixes to determine if the string being converted qualifies as a credit card number. This DOES NOT check to see if an actual card with the specified number exists, only that it appears to be a valid card number.
If the credit card number is not valid a single error message will be generated. The error message is a scoped message with a default scope of converter.creditCard and name invalidCreditCard. As a result error messages will be looked for in the following order:
Modifier and Type | Class and Description |
---|---|
static class |
CreditCardTypeConverter.Type |
Constructor and Description |
---|
CreditCardTypeConverter() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
convert(java.lang.String input,
java.lang.Class<? extends java.lang.String> targetType,
java.util.Collection<ValidationError> errors)
Validates the user input to ensure that it looks like a valid credit card number.
|
static CreditCardTypeConverter.Type |
getCardType(java.lang.String cardNumber)
Determines the type of card from the card number passed in.
|
void |
setLocale(java.util.Locale locale)
Accepts the Locale provided, but does nothing with it since credit card numbers are Locale-less.
|
public void setLocale(java.util.Locale locale)
setLocale
in interface TypeConverter<java.lang.String>
locale
- the locale that the TypeConverter will be converting from.public java.lang.String convert(java.lang.String input, java.lang.Class<? extends java.lang.String> targetType, java.util.Collection<ValidationError> errors)
convert
in interface TypeConverter<java.lang.String>
input
- the String input, always a non-null non-empty StringtargetType
- realistically always String since java.lang.String is finalerrors
- a non-null collection of errors to populate in case of errorpublic static CreditCardTypeConverter.Type getCardType(java.lang.String cardNumber)
cardNumber
- the card number to check? Copyright 2005-2006, Stripes Development Team.