Class RegexValidator

java.lang.Object
com.alibaba.fastjson2.util.RegexValidator

public class RegexValidator extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a case sensitive validator for a single regular expression.
    Construct a case sensitive validator that matches any one of the set of regular expressions.
    RegexValidator(String[] regexs, boolean caseSensitive)
    Construct a validator that matches any one of the set of regular expressions with the specified case sensitivity.
    RegexValidator(String regex, boolean caseSensitive)
    Construct a validator for a single regular expression with the specified case sensitivity.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isValid(String value)
    Validate a value against the set of regular expressions.
    match(String value)
    Validate a value against the set of regular expressions returning the array of matched groups.
    Provide a String representation of this validator.
    Validate a value against the set of regular expressions returning a String value of the aggregated groups.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RegexValidator

      public RegexValidator(String regex)
      Construct a case sensitive validator for a single regular expression.
      Parameters:
      regex - The regular expression this validator will validate against
    • RegexValidator

      public RegexValidator(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
    • RegexValidator

      public RegexValidator(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
    • RegexValidator

      public RegexValidator(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 Details

    • isValid

      public boolean isValid(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.
    • match

      public String[] match(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
    • validate

      public String validate(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
    • toString

      public String toString()
      Provide a String representation of this validator.
      Overrides:
      toString in class Object
      Returns:
      A String representation of this validator