1 package org.sapia.validator.rules; 2 3 import java.util.regex.Matcher ; 4 import java.util.regex.Pattern ; 5 import org.sapia.validator.BeanRule; 6 7 17 public class RegEx extends BeanRule{ 18 19 private Pattern _patternObj; 20 21 24 public RegEx() { 25 super.throwExceptionOnNull(true); 26 } 27 28 33 public void setPattern(String pattern){ 34 _patternObj = Pattern.compile(pattern); 35 } 36 37 40 protected boolean doValidate(Object toValidate) { 41 if(_patternObj == null){ 42 throw new IllegalStateException ("'pattern' attribute not defined on regExp rule at " + qualifiedName()); 43 } 44 Matcher matcher = _patternObj.matcher(toValidate.toString()); 45 return matcher.matches(); 46 } 47 48 49 } 50 | Popular Tags |