skander bjk :
I am trying to develop a simple REGEX in Java with pattern like that :
@Pattern(regexp = "[a-zA-Z]{2}[0-9]{1}[2-8]{1}" , message = "The format is invalid")
but this message is still displayed when the field is empty, so i want to show this message only when the field is not empty (i want that the field is will be not required).
Thank you.
Tim Biegeleisen :
Try using the following regex, which matches both your expected string and empty string:
[a-zA-Z]{2}[0-9]{1}[2-8]{1}|^$
Java code:
@Pattern(regexp = "[a-zA-Z]{2}[0-9]{1}[2-8]{1}|^$", message = "The format is invalid")
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=306088&siteId=1