According to the Apache docs, their email validation respects the RFC 822 specification.
EmailValidator provides email address validation according to RFC 822 standards. source
However when running some tests locally I found that some TLD's are accepted as a domain.
test@test //invalid
[email protected] //valid
test@com //valid
test@comm //invalid
test@amsterdam //valid
test@brussels //valid
I thought I read somewhere in the RFC that <local>@<domain> is a valid e-mail address but highly discouraged to use (..and thus should be considered invalid?). So I get that test@test will not be valid, however test@amsterdam is, because .amsterdam is a valid gTLD.
Not sure if this is a bug or if this is intended. From their implementation and documentation it is unclear what should be valid, and if it is 100% comform the RFC 822 specification.
class Test {
EmailValidator validator = EmailValidator.getInstance(false, true);
@ParameterizedTest
@ValueSource(strings = {
"test@test",
"[email protected]",
"test@com",
"test@comm",
"test@amsterdam",
"test@brussels"
})
void emails(String email) {
System.out.printf("%-20s valid? %s%n", email, validator.isValid(email));
}
}
What I also don't seem to get is what the parameters allowLocal and allowTld in the EmailValidator constructor do
I would say this is intended. You can adjust validation to your by providing parameters you've mentioned.
According to https://www.icann.org/en/announcements/details/new-gtld-dotless-domain-names-prohibited-30-8-2013-en dotless domains are prohibited.
And as a word of explanation for parameters:
allowLocal- will allow local domains e.gmail@somenotexistingtldallowTld- will allow top level domains e.gmail@comTo have truly accurate RFC822 validation you need set both to
true. But in real life scenario I would say that in most of the cases they will be omitted or set tofalse.