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?
Try @Pattern(regex=".{5}|.{9}") (change the dot to another character class if you don't want to match everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With