Class TINValidator
java.lang.Object
org.apache.commons.validator.routines.TINValidator
Tax identification number (TIN) Validator.
The validator includes a default set of formats and check routines for countries
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:
TINValidator v = new TINValidator();
v.setValidator("AT", 9, "\\d{9}", TidATCheckDigit.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 TINValidatorThe singleton instance which uses the default formats -
Constructor Summary
ConstructorsConstructorDescriptionCreate a default validator.TINValidator(TINValidator.Validator[] validators) Create an IN validator from the specified map of TIN formats. -
Method Summary
Modifier and TypeMethodDescriptionGets a copy of the default Validators.static TINValidatorGets the singleton instance of the validator using the default formatsgetValidator(String cc) Gets the Validator for a given countrybooleanhasValidator(String cc) Does the class have the required validator?booleanValidate a TIN CodesetValidator(String countryCode, int length, String format, CheckDigit routine) Installs a validator.setValidator(TINValidator.Validator validator) Installs a validator.
-
Field Details
-
DEFAULT_TIN_VALIDATOR
The singleton instance which uses the default formats
-
-
Constructor Details
-
TINValidator
public TINValidator()Create a default validator. -
TINValidator
Create an IN validator from the specified map of TIN formats.- Parameters:
validators- map of TIN formats
-
-
Method Details
-
getInstance
Gets the singleton instance of the 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 country- Parameters:
cc- the ISO country code- Returns:
- the validator or
nullif there is no one registered.
-
hasValidator
Does the class have the required validator?- Parameters:
cc- the ISO country code- Returns:
- true if there is a validator for the country
-
isValid
Validate a TIN Code- Parameters:
cc- the country codecode- The value validation is being performed on (e.g. "02476291358" a DE TestID)- Returns:
trueif the value is valid
-
setValidator
public TINValidator.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 TIN. 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 TIN 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
-