Class TINValidator

java.lang.Object
org.apache.commons.validator.routines.TINValidator

public class TINValidator extends Object
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
  • Field Details

    • DEFAULT_TIN_VALIDATOR

      public static final TINValidator DEFAULT_TIN_VALIDATOR
      The singleton instance which uses the default formats
  • Constructor Details

    • TINValidator

      public TINValidator()
      Create a default validator.
    • TINValidator

      public TINValidator(TINValidator.Validator[] validators)
      Create an IN validator from the specified map of TIN formats.
      Parameters:
      validators - map of TIN formats
  • Method Details

    • getInstance

      public static TINValidator getInstance()
      Gets the singleton instance of the validator using the default formats
      Returns:
      A singleton instance of the validator
    • getDefaultValidators

      public TINValidator.Validator[] getDefaultValidators()
      Gets a copy of the default Validators.
      Returns:
      a copy of the default Validator array
    • getValidator

      public TINValidator.Validator getValidator(String cc)
      Gets the Validator for a given country
      Parameters:
      cc - the ISO country code
      Returns:
      the validator or null if there is no one registered.
    • hasValidator

      public boolean hasValidator(String cc)
      Does the class have the required validator?
      Parameters:
      cc - the ISO country code
      Returns:
      true if there is a validator for the country
    • isValid

      public boolean isValid(String cc, String code)
      Validate a TIN Code
      Parameters:
      cc - the country code
      code - The value validation is being performed on (e.g. "02476291358" a DE TestID)
      Returns:
      true if 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 code
      length - 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 null if there was none
      Throws:
      IllegalArgumentException - if there is a problem
      IllegalStateException - if an attempt is made to modify the singleton validator
    • setValidator

      public TINValidator.Validator setValidator(TINValidator.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:
      IllegalStateException - if an attempt is made to modify the singleton validator