Class IBANValidator
java.lang.Object
org.apache.commons.validator.routines.IBANValidator
IBAN Validator.
The validator includes a default set of formats derived from the IBAN registry at https://www.swift.com/standards/data-standards/iban.
This can get out of date, but the set can be adjusted by creating a validator and using the
setValidator(String, int, String)
or
setValidator(Validator)
method to add (or remove) an entry.
For example:
IBANValidator ibv = new IBANValidator(); ibv.setValidator("XX", 12, "XX\\d{10}")
The singleton default instance cannot be modified in this way.
- Since:
- 1.5.0
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final IBANValidator
The singleton instance which uses the default formats -
Constructor Summary
ConstructorDescriptionCreate a default IBAN validator.IBANValidator
(IBANValidator.Validator[] validators) Create an IBAN validator from the specified map of IBAN formats. -
Method Summary
Modifier and TypeMethodDescriptionGets a copy of the default Validators.static IBANValidator
Gets the singleton instance of the IBAN validator using the default formatsgetValidator
(String code) Gets the Validator for a given IBANboolean
hasValidator
(String code) Does the class have the required validator?boolean
Validate an IBAN CodesetValidator
(String countryCode, int length, String format) Installs a validator.setValidator
(IBANValidator.Validator validator) Installs a validator.
-
Field Details
-
DEFAULT_IBAN_VALIDATOR
The singleton instance which uses the default formats
-
-
Constructor Details
-
IBANValidator
public IBANValidator()Create a default IBAN validator. -
IBANValidator
Create an IBAN validator from the specified map of IBAN formats.- Parameters:
validators
- map of IBAN formats
-
-
Method Details
-
getInstance
Gets the singleton instance of the IBAN validator using the default formats- Returns:
- A singleton instance of the IBAN validator
-
getDefaultValidators
Gets a copy of the default Validators.- Returns:
- a copy of the default Validator array
-
getValidator
Gets 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.
-
hasValidator
Does the class have the required validator?- Parameters:
code
- the code to check- Returns:
- true if there is a validator
-
isValid
Validate an IBAN Code- Parameters:
code
- The value validation is being performed on- Returns:
true
if the value is valid
-
setValidator
Installs a validator. Will replace any existing entry which has the same countryCode.- Parameters:
countryCode
- the country codelength
- 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:
IllegalArgumentException
- if there is a problemIllegalStateException
- if an attempt is made to modify the singleton validator
-
setValidator
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:
IllegalStateException
- if an attempt is made to modify the singleton validator
-