Is there an annotation for springbote that makes it possible to only allow certain emails as email.
The email should only end with @ companyname.com
Is there an annotation for springbote that makes it possible to only allow certain emails as email.
The email should only end with @ companyname.com
Your question is already answered by this thread
You can use the @Email constraint from javax.validation.constraint .
Per default the regular expression of the email constraint allows everything. So for you case following can be done:
@Email(regex = "\W*((?i)@companyname.com(?-i))")
private String mail;
If you wished you can also modify the default constraint violation message.
Remember of course to add the needed dependency if not already provided e.g
implementation 'org.springframework.boot:spring-boot-starter-validation:2.4.0'