I can validate the length of a String with an annotation like:
@Length(max = 255)
But what if I want to verifiy that the length is either 5 or 9? Can this be done with an annotation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s the documentation for implementing custom constraint.
It’s fairly simple:
So perhaps your annotation might look like: