Hi, I created a validator like below. It seemed that it did not work, and there was not error message.
I use JBoss Seam 2.0.1
Code:
@Documented
@ValidatorClass(PhoneValidator.class)
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface PhoneValid {
String message() default "{validator.phone}";
}
Code:
public class PhoneValidator implements Validator<PhoneValid>, Serializable {
private static final long serialVersionUID = -1049632944485567414L;
private Pattern pattern;
public void initialize(PhoneValid parameter) {
System.out.println(parameter.message());
pattern = Pattern
.compile("^(\\(?\\d\\d\\d\\)?)?( |-|\\.)?\\d\\d\\d( |-|\\.)?\\d{4,4}(( |-|\\.)?[ext\\.]+ ?\\d+)?$");
}
public boolean isValid(Object value) {
if (value == null)
return true;
if (!(value instanceof String))
return false;
String string = (String) value;
if (string.length() == 0)
return true;
Matcher m = pattern.matcher(string);
return m.matches();
}
}
Code:
@Column(name="secondary_phone", length=40)
@PhoneValid
private String secondaryPhone;