Class VATINValidator
java.lang.Object
org.apache.commons.validator.routines.VATINValidator
VAT identification number (VATIN) Validator.
The validator includes a default set of formats and check routines for European Union countries, see https://en.wikipedia.org/wiki/VAT_identification_number
This can be adjusted f.i. adding a new country routines by creating a validator and using the
setValidator(String, int, String, CheckDigit)
method to add (or remove) an entry.
For example:
VATINValidator v = new VATINValidator();
v.setValidator("GB", 14, "GB(\\d{3})?\\d{9}", VATidGBCheckDigit.getInstance());
The singleton default instance cannot be modified in this way.
- Since:
- 1.10.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VATINValidatorThe singleton instance which uses the default formats -
Constructor Summary
ConstructorsConstructorDescriptionCreate a default validator.VATINValidator(VATINValidator.Validator[] validators) Create an VATIN validator from the specified map of VATIN formats. -
Method Summary
Modifier and TypeMethodDescriptionGets a copy of the default Validators.static VATINValidatorGets the singleton instance of the VATIN validator using the default formatsgetValidator(String code) Gets the Validator for a given VATINbooleanhasValidator(String code) Does the class have the required validator?booleanValidate a VATIN CodesetValidator(String countryCode, int length, String format, CheckDigit routine) Installs a validator.setValidator(VATINValidator.Validator validator) Installs a validator.
-
Field Details
-
DEFAULT_VATIN_VALIDATOR
The singleton instance which uses the default formats
-
-
Constructor Details
-
VATINValidator
public VATINValidator()Create a default validator. -
VATINValidator
Create an VATIN validator from the specified map of VATIN formats.- Parameters:
validators- map of VATIN formats
-
-
Method Details
-
getInstance
Gets the singleton instance of the VATIN validator using the default formats- Returns:
- A singleton instance of the validator
-
getDefaultValidators
Gets a copy of the default Validators.- Returns:
- a copy of the default Validator array
-
getValidator
Gets the Validator for a given VATIN- Parameters:
code- a string starting with the ISO country code (e.g. "BG831650349" Nestlé.bg)- Returns:
- the validator or
nullif there is no one registered.
-
hasValidator
Does the class have the required validator?- Parameters:
code- the code to check- Returns:
- true if there is a validator for the country
-
isValid
Validate a VATIN Code- Parameters:
code- The value validation is being performed on (e.g. "BG831650349" Nestlé.bg)- Returns:
trueif the value is valid
-
setValidator
public VATINValidator.Validator setValidator(String countryCode, int length, String format, CheckDigit routine) Installs a validator. Will replace any existing entry which has the same countryCode.- Parameters:
countryCode- the country codelength- the length of the VATIN. 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 VATIN for the country (as a regular expression)routine- the CheckDigit module- Returns:
- the previous Validator, or
nullif 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
nullif there was none - Throws:
IllegalStateException- if an attempt is made to modify the singleton validator
-