I am new in validation.
controller:
@Validated
@RestController
public class AccountController
{
@PostMapping( value = "/account/location" )
public ResponseEntity<LocationAccountVO> createLocationAccount( @RequestHeader
HttpHeaders headers,@Valid @RequestBody LocationAccountVO locationAccountVO ) throws
NumberParseException
{
return ResponseEntity.status(HttpStatus.CREATED).body(
accountService.createLocationAccount( locationAccountVO ) );
}
}
LoacationVo.java:
@Data
@JsonInclude( JsonInclude.Include.NON_NULL )
public class LocationAccountVO
{
private UUID locationId;
@NotNull(message = "Email is mandatory.")
@Email( regexp = ValidationConstant.EMAIL, message = "Email be valid")
private String email;
}
public static final String EMAIL = "\\\\b[A-Z]+@[A-Z0-9.-]+\\\\.[A-Z]{2,4}\\\\b";
but @Email not giving custom message and pattern also not working.Kindly solve my problem.
Thanks.
\\. Actually, the\\bat both ends are redundant, remove them.\b[A-Z]+@[A-Z0-9]+\\.[A-Z]{2,4}\bis this correct?[email protected]^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@?matches,public static final String EMAIL = "[A-Z]+@[A-Z0-9.-]+\\.[A-Z]{2,4}";should be enough. But it is too restrictive. Consider something like"\\S+@\\S+\\.\\S+"