Class TravelDocumentValidator
java.lang.Object
org.apache.commons.validator.routines.TravelDocumentValidator
Travel Document Validator.
The validator includes a default set of formats to check numbers of passports, ID-cards and visas.
For further information see Wikipedia. See International Civil Aviation Organization, Doc 9303: Machine Readable Travel Documents, Part 3: Specifications Common to all MRTDs for more details.
This can be adjusted f.i. adding a new country routines by creating a validator and using the
setValidator(Type, String, int, String, CheckDigit)
method to add (or remove) an entry.
For example:
TravelDocumentValidator v = new TravelDocumentValidator();
v.setValidator(P, "TWN", "\\d{10}", Modulus10_731CheckDigit.getInstance());
The singleton default instance cannot be modified in this way.
- Since:
- 2.10.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe International Civil Aviation Organization (ICAO) defines travel document standards in Doc 9303.static classThe validation class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TravelDocumentValidatorThe singleton instance which uses the default formats -
Constructor Summary
ConstructorsConstructorDescriptionCreate a default validator.TravelDocumentValidator(TravelDocumentValidator.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 TravelDocumentValidatorGets the singleton instance of the validator using the default formatsGets the Validator for a given type and countrybooleanDoes the class have the required validator?booleanisValid(TravelDocumentValidator.Type t, String cc, String code) Validate a travel documentsetValidator(TravelDocumentValidator.Type t, String cc, int length, String format, CheckDigit routine) Installs a validator.setValidator(TravelDocumentValidator.Validator validator) Installs a validator.
-
Field Details
-
DEFAULT_VALIDATOR
The singleton instance which uses the default formats
-
-
Constructor Details
-
TravelDocumentValidator
public TravelDocumentValidator()Create a default validator. -
TravelDocumentValidator
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 type and country- Parameters:
t- the ICAO document typecc- the ICAO country code- Returns:
- the validator or
nullif there is no one registered.
-
hasValidator
Does the class have the required validator?- Parameters:
t- the ICAO document typecc- the ICAO country code- Returns:
- true if there is a validator for the country
-
isValid
Validate a travel document- Parameters:
t- the ICAO document typecc- the ICAO country codecode- The value validation is being performed on (e.g. "9102392482" an USA Passport)- Returns:
trueif the value is valid
-
setValidator
public TravelDocumentValidator.Validator setValidator(TravelDocumentValidator.Type t, String cc, int length, String format, CheckDigit routine) Installs a validator. Will replace any existing entry which has the same countryCode.- Parameters:
t- the ICAO document typecc- the ICAO 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
-