Regex not required

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.