RegexValidator (Grails 3.1.10)
Date: 2016-07-28

Package: org.grails.validation.routines

## [Java] Class RegexValidator

- org.grails.validation.routines.RegexValidator

- All Implemented Interfaces and Traits:
    java.io.Serializable

      public class RegexValidator
      extends java.lang.Object

  Regular Expression validation (using JDK 1.4+ regex support).

  Construct the validator either for a single regular expression or a set (array) of regular expressions. By default validation is case sensitive but constructors are provided to allow case in-sensitive validation. For example to create a validator which does case in-sensitive validation for a set of regular expressions:

               String[] regexs = new String[] {...};
               RegexValidator validator = new RegexValidator(regexs, false);

  - Validate `true` or `false`:
  - `boolean valid = validator.isValid(value);`
  - Validate returning an aggregated String of the matched groups:
  - `String result = validator.validate(value);`
  - Validate returning the matched groups:
  - `String[] result = validator.match(value);`

  Cached instances pre-compile and re-use java.util.regex.Pattern(s) - which according to the java.util.regex.Pattern API are safe to use in a multi-threaded environment.

  Since:
    Validator 1.4

- - ### Constructor Summary

    Constructors
    Constructor and description
    `RegexValidator (java.lang.String regex)` Construct a case sensitive validator for a single regular expression.
    `RegexValidator (java.lang.String regex, boolean caseSensitive)` Construct a validator for a single regular expression with the specified case sensitivity.
    `RegexValidator (java.lang.String[] regexs)` Construct a case sensitive validator that matches any one of the set of regular expressions.
    `RegexValidator (java.lang.String[] regexs, boolean caseSensitive)` Construct a validator that matches any one of the set of regular expressions with the specified case sensitivity.

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `boolean` | `isValid(java.lang.String value)` Validate a value against the set of regular expressions.
    `java.lang.String[]` | `match(java.lang.String value)` Validate a value against the set of regular expressions returning the array of matched groups.
    `java.lang.String` | `toString()` Provide a String representation of this validator.
    `java.lang.String` | `validate(java.lang.String value)` Validate a value against the set of regular expressions returning a String value of the aggregated groups.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### public RegexValidator(java.lang.String regex)

      Construct a case sensitive validator for a single regular expression.

      Parameters:
        `regex` - The regular expression this validator will validate against

    - #### public RegexValidator(java.lang.String regex, boolean caseSensitive)

      Construct a validator for a single regular expression with the specified case sensitivity.

      Parameters:
        `regex` - The regular expression this validator will validate against
        `caseSensitive` - when `true` matching is case sensitive, otherwise matching is case in-sensitive

    - #### public RegexValidator(java.lang.String[] regexs)

      Construct a case sensitive validator that matches any one of the set of regular expressions.

      Parameters:
        `regexs` - The set of regular expressions this validator will validate against

    - #### public RegexValidator(java.lang.String[] regexs, boolean caseSensitive)

      Construct a validator that matches any one of the set of regular expressions with the specified case sensitivity.

      Parameters:
        `regexs` - The set of regular expressions this validator will validate against
        `caseSensitive` - when `true` matching is case sensitive, otherwise matching is case in-sensitive

  - ### Method Detail

    - #### public boolean isValid(java.lang.String value)

      Validate a value against the set of regular expressions.

      Parameters:
        `value` - The value to validate.
      Returns:
        `true` if the value is valid otherwise `false`.

    - #### public java.lang.String[] match(java.lang.String value)

      Validate a value against the set of regular expressions returning the array of matched groups.

      Parameters:
        `value` - The value to validate.
      Returns:
        String array of the groups matched if valid or `null` if invalid

    - #### @java.lang.Override public java.lang.String toString()

      Provide a String representation of this validator.

      Returns:
        A String representation of this validator

    - #### public java.lang.String validate(java.lang.String value)

      Validate a value against the set of regular expressions returning a String value of the aggregated groups.

      Parameters:
        `value` - The value to validate.
      Returns:
        Aggregated String value comprised of the groups matched if valid or `null` if invalid