1 12 13 package org.eclipse.jface.internal.databinding.provisional.validation; 14 15 import java.util.regex.Matcher ; 16 import java.util.regex.Pattern ; 17 18 19 23 public class RegexStringValidator implements IValidator { 24 25 private Pattern fragmentRegex; 26 private Pattern fullValueRegex; 27 private String hint; 28 29 39 public RegexStringValidator(String partiallyValidRegex, 40 String fullyValidRegex, String hint) { 41 super(); 42 this.fragmentRegex = Pattern.compile(partiallyValidRegex); 43 this.fullValueRegex = Pattern.compile(fullyValidRegex); 44 this.hint = hint; 45 } 46 47 50 public ValidationError isPartiallyValid(Object fragment) { 51 Matcher matcher = fragmentRegex.matcher((String )fragment); 52 if (matcher.find()) 53 return null; 54 55 return ValidationError.error(hint); 56 } 57 58 61 public ValidationError isValid(Object value) { 62 String stringValue = (String ) value; 63 Matcher matcher = fullValueRegex.matcher(stringValue); 64 if (matcher.find()) 65 return null; 66 67 return ValidationError.error(hint); 68 } 69 70 } 71 | Popular Tags |