01: package org.jreform.criteria;
02:
03: import java.util.regex.Pattern;
04:
05: /**
06: * Checks if a string matches a regular expression.
07: *
08: * @author armandino (at) gmail.com
09: */
10: public class Regex extends AbstractCriterion<String> {
11: private Pattern pattern;
12:
13: Regex(String pattern) {
14: this .pattern = Pattern.compile(pattern);
15: }
16:
17: protected boolean verify(String value) {
18: return pattern.matcher(value).find();
19: }
20:
21: protected String generateErrorMessage() {
22: return "The value must match the required format";
23: }
24:
25: }
|