Home > Software engineering >  Pattern constraints for a list of strings
Pattern constraints for a list of strings

Time:11-18

I have a List<String> that contains a list of emails, something like
{"[email protected]", "[email protected]"}

The problem is I don't really know how to create a @Pattern, and I want to put the condition that the pattern should only allow emails from list that ends with @gmail.com. I used

@Pattern(regexp = "^(. )@(. )$")

for the case when I had a String, not a List.

CodePudding user response:

You may need to refer to the documentation of Container element constraints.

List<@Pattern(regexp = "^(. )@(gmail.com)$") String> mails;

Reference: https://beanvalidation.org/2.0/spec/#constraintdeclarationvalidationprocess-containerelementconstraints

  • Related