Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate-validator @email length greater then 64 characters

I used hibernate-validator @Email and @Length for request validator. As this. Code

    @XmlElement
@Email(message = APIConstants.ERROR_INVALID_FIELD)
@Length(max = 128, message = APIConstants.ERROR_INVALID_FIELD)
@NotEmpty(message = APIConstants.ERROR_MISSING_FIELD)
private String email;

I find that if the length of email is greater then 64 characters, then it will be invalid. If I remove the @Email, then it can be greater then 64 characters.So I think the @Email limit the length of email to 64 characters. I want to use @Email,but i want the length of email is limited to 128 characters. How to do it.

like image 781
Andrew Shen Avatar asked Dec 05 '25 22:12

Andrew Shen


1 Answers

Hard to say without an example of an email failing.

The local part of an email is limited to 64 characters (domain excluded). Maybe that's the limit you're having?

See https://en.wikipedia.org/wiki/Email_address:

The format of email addresses is local-part@domain where the local part may be up to 64 characters long and the domain may have a maximum of 255 characters.

Our validator (https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/AbstractEmailValidator.java) is not perfect but it's supposed to be lenient and accept all valid email addresses (and a few invalid ones too).

If you have an example of a valid email address that is not accepted, please provide it.

like image 50
Guillaume Smet Avatar answered Dec 09 '25 20:12

Guillaume Smet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!