Class IBANValidator
- java.lang.Object
-
- org.apache.commons.validator.routines.IBANValidator
-
public class IBANValidator extends java.lang.Object
IBAN Validator.- Since:
- 1.5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IBANValidator.Validator
-
Field Summary
Fields Modifier and Type Field Description private static IBANValidator.Validator[]
DEFAULT_FORMATS
static IBANValidator
DEFAULT_IBAN_VALIDATOR
private java.util.Map<java.lang.String,IBANValidator.Validator>
formatValidators
-
Constructor Summary
Constructors Constructor Description IBANValidator()
Create a default IBAN validator.IBANValidator(IBANValidator.Validator[] formatMap)
Create an IBAN validator from the specified map of IBAN formats.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.Map<java.lang.String,IBANValidator.Validator>
createValidators(IBANValidator.Validator[] formatMap)
IBANValidator.Validator[]
getDefaultValidators()
Gets a copy of the default Validators.static IBANValidator
getInstance()
Return a singleton instance of the IBAN validator using the default formatsIBANValidator.Validator
getValidator(java.lang.String code)
Get the Validator for a given IBANboolean
hasValidator(java.lang.String code)
Does the class have the required validator?boolean
isValid(java.lang.String code)
Validate an IBAN Code.IBANValidator.Validator
setValidator(java.lang.String countryCode, int length, java.lang.String format)
Installs a validator.IBANValidator.Validator
setValidator(IBANValidator.Validator validator)
Installs a validator.
-
-
-
Field Detail
-
formatValidators
private final java.util.Map<java.lang.String,IBANValidator.Validator> formatValidators
-
DEFAULT_FORMATS
private static final IBANValidator.Validator[] DEFAULT_FORMATS
-
DEFAULT_IBAN_VALIDATOR
public static final IBANValidator DEFAULT_IBAN_VALIDATOR
-
-
Constructor Detail
-
IBANValidator
public IBANValidator()
Create a default IBAN validator.
-
IBANValidator
public IBANValidator(IBANValidator.Validator[] formatMap)
Create an IBAN validator from the specified map of IBAN formats.- Parameters:
formatMap
- map of IBAN formats
-
-
Method Detail
-
getInstance
public static IBANValidator getInstance()
Return a singleton instance of the IBAN validator using the default formats- Returns:
- A singleton instance of the ISBN validator
-
createValidators
private java.util.Map<java.lang.String,IBANValidator.Validator> createValidators(IBANValidator.Validator[] formatMap)
-
isValid
public boolean isValid(java.lang.String code)
Validate an IBAN Code.
- Parameters:
value
- The value validation is being performed on- Returns:
true
if the value is valid
-
hasValidator
public boolean hasValidator(java.lang.String code)
Does the class have the required validator?- Parameters:
code
- the code to check- Returns:
- true if there is a validator
-
getDefaultValidators
public IBANValidator.Validator[] getDefaultValidators()
Gets a copy of the default Validators.- Returns:
- a copy of the default Validator array
-
getValidator
public IBANValidator.Validator getValidator(java.lang.String code)
Get the Validator for a given IBAN- Parameters:
code
- a string starting with the ISO country code (e.g. an IBAN)- Returns:
- the validator or
null
if there is not one registered.
-
setValidator
public IBANValidator.Validator setValidator(IBANValidator.Validator validator)
Installs a validator. Will replace any existing entry which has the same countryCode- Parameters:
validator
- the instance to install.- Returns:
- the previous Validator, or
null
if there was none - Throws:
java.lang.IllegalStateException
- if an attempt is made to modify the singleton validator
-
setValidator
public IBANValidator.Validator setValidator(java.lang.String countryCode, int length, java.lang.String format)
Installs a validator. Will replace any existing entry which has the same countryCode.- Parameters:
countryCode
-length
- the length of the IBAN. Must be ≥ 8 and ≤ 32. If the length is < 0, the validator is removed, and the format is not used.format
- the format of the IBAN (as a regular expression)- Returns:
- the previous Validator, or
null
if there was none - Throws:
java.lang.IllegalArgumentException
- if there is a problemjava.lang.IllegalStateException
- if an attempt is made to modify the singleton validator
-
-