RegexValidator implements Serializable { public String validate(String value) { if (value == null) { return null; } for (Pattern pattern : patterns) { Matcher matcher = pattern.matcher(value); if (matcher.matches()) { int count = matcher.groupCount(); if (count == 1) { return matcher.group(1); } StringBuilder buffer = new StringBuilder(); for (int j = 0; j < count; j++) { String component = matcher.group(j + 1); if (component != null) { buffer.append(component); } } return buffer.toString(); } } return null; } RegexValidator(String regex);  RegexValidator(String regex, boolean caseSensitive);  RegexValidator(String[] regexs);  RegexValidator(String[] regexs, boolean caseSensitive); boolean isValid(String value); String[] match(String value); String validate(String value); @Override String toString();  }
@Test public void testValidate() { RegexValidator regexValid = new RegexValidator(DOMAIN_LABEL_REGEX); assertEquals("", regexValid.validate("aabb")); assertEquals(null, regexValid.validate("sina.com")); assertEquals(null, regexValid.validate(null)); }