Interface RegexValidator
- All Superinterfaces:
Cloneable
,Validator
,ValueValidator
- All Known Implementing Classes:
RegexValidatorImpl
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.validate.api.validators.Validator
Validator.MergeMode
-
Method Summary
Methods inherited from interface ch.tocco.nice2.validate.api.validators.Validator
canMergeConstraints, clone, doContinueOnFailure, doNegate, getLevel, getName, getRunOn, getType, hasName, mergeConstraints, setContinue, setLevel, setName, setNegate, setRunOn, validate
-
Method Details
-
init
See class header. -
init
See class header. -
init
See class header. -
getPattern
Pattern getPattern()
-