A Custom Converter for Credit Card Numbers
A user should be able to enter credit card numbers with or without spaces:
1234567890123456
1234 5678 9012 3456
The getAsObject method for a custom credit card converter should:
- Strip out all characters that are not digits
- Create an object of type
CreditCard.
The getAsString method for a custom credit card converter should:
- Format the credit card number in a way that is pleasing to the eye of
the user
- Digits should be separated into familiar patterns, depending on the
credit card type.
Here is a
CreditCardConverter.java class that implements
javax.faces.converter.Converter.