java - Struts2 Annotations validate String using RegexFieldValidator -
i trying use struts2 annotations validate fields of bean. in case, validate phone number string regex.
i found @regexfieldvalidator
annotation, included in class , made tests:
@requiredstringvalidator(message="phone required.") @regexfieldvalidator( message="invalid phone", expression="\\([\\d][\\d][\\d]\\) [\\d][\\d][\\d]-[\\d][\\d][\\d][\\d]") public void setphone(string phone) { this.phone = phone; }
however, regex expression doesn´t work. tried "\d{9}" , "[0-9]{9}". type=validatortype.simple.
the required stringvalidator works properly...what´s going on here? possible use validator properly?
thanks in advance
try with
@regexfieldvalidator(type=validatortype.field, message="invalid phone", expression="\\([0-9][0-9][0-9]\\)\\s[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")
Comments
Post a Comment