Interface RegexValidator

All Superinterfaces:
Cloneable, Validator, ValueValidator
All Known Implementing Classes:
RegexValidatorImpl

public interface RegexValidator extends ValueValidator
Validator that acts based on regular expressions.

Examples

RegexValidator v = new RegexValidatorImpl(); v.init("^[+-]?[0-9]+$") RegexValidator v = new RegexValidatorImpl(); v.init("^[a-z]*$", Pattern.CASE_INSENSITIVE)

Notes on defining the regex

COMPATIBILITY: Either the regex must be fully compatible to both Java and JavaScript, or the validator must use the run-on feature. So you may want to use two separate ones for special cases.

BOUNDARIES: Use the start ^ and end $ boundaries if the whole string must match. Technically, the Java side matches the regex as 'whole' while JS as 'contains' if you do not specify the boundaries.

 Examples:
 regex       string     java         js
 "[a-z]*"    "123"      false        true (it contains a-z zero or more times, zero in this case)
 "^[a-z]$*"  "123"      false        false (that's what you want)
 

TEST: Always test your regex.

  • Method Details

    • init

      void init(String regex)
      See class header.
    • init

      void init(String regex, int bitmask)
      See class header.
    • init

      void init(Pattern pattern)
      See class header.
    • getPattern

      Pattern getPattern()