Reputation: 1375
I am validating a bean with JSR 303 specifications, it has a parameter that contains list of string. I want to validate each string in this list as this is the request object. I already have a pattern for matching each string, but i am not able to apply if recursively for each entry in the list.
@NotEmpty(message = "phoneNumber must not be null or empty")
@Valid @Pattern(regexp = REGEX_PHONENUMBER, message = "Not a valid phoneNumber")
private List<String> phoneNumber;
Upvotes: 2
Views: 792
Reputation: 1959
A custom validator need to be implemented to make it possible using JSR 303
@PhoneNumbers
private List<String> phoneNumber;
It's supported out of the box in Bean Validation 2.0 / JSR 380:
List<@NotEmpty @Pattern(regexp = REGEX_PHONENUMBER) String>
Upvotes: 3