I use Hibernate Validation 4.3.1.Final and Spring 3.2.0.RELEASE
I have a form with a string attribute. This attribute is not required, but if it contains some value this value should be exactly 10 digits length. So I need somthing like:
@NotRquired
@Length(min = 10, max = 10)
But there is no annotation like @NotRquired. How I should write validation for this case?
Not that a @NotRquired annotation would not help in this case, because all defined constraints are evaluated. So in the case where the value is not specified @Length would still be validated and fail. There are several things you could do:\