Class RegexValidator

java.lang.Object
org.apache.sling.validation.impl.validators.RegexValidator
All Implemented Interfaces:
Validator<String>

public class RegexValidator extends Object implements Validator<String>
Performs regular expressions validation on the supplied data with the help of the Pattern class. This Validator expects a mandatory parameter in the arguments map: REGEX_PARAM.
  • Field Details

  • Constructor Details

    • RegexValidator

      public RegexValidator()
  • Method Details

    • validate

      @Nonnull public ValidationResult validate(@Nonnull String data, @Nonnull ValidatorContext context, @Nonnull ValueMap arguments) throws SlingValidationException
      Description copied from interface: Validator
      Validates the data and/or the valueMap according to the internal constraints of this validator. The validator can enforce the type of the given data just by setting the appropriate parameter type T which can be any non-primitive class. Depending on whether this type is an array or not the validate method is called differently:
      T is array type Valuemap contains array value validate is called...
      yes yes once per property with data containing the full array
      yes no once per property with data containing a single element array
      no yes once per element in the property array with data containing one array element
      no no once per property with data containing the value of the property
      If the data cannot be converted into the type T the validator is not called, but validation fails.
      Specified by:
      validate in interface Validator<String>
      Parameters:
      data - the data to validate (primary property), never null.
      context - the validation context contains additional information about the data to be validated, never null.
      arguments - the parameterization of the validator. Never null but might be the empty map.
      Returns:
      the validation result (encapsulates the validation status as well as messages).
      Throws:
      SlingValidationException - if some expected arguments are missing from the arguments map