Reputation: 529
While using Apache common Email validator as below link:
it returns false positive result for email formatted as :
[email protected] -> true
random.bla@gmail -> true
is there a better way to validate emails?
Upvotes: 0
Views: 538
Reputation: 991
Apache common email validator valid when email address has & char but it is not true.
assertFalse(EmailValidatorUtil.isValid("asdfasd&@hotmail.com"));
Upvotes: 0
Reputation: 13281
For "static validation", only the newest commons-validator version can help/improve.
see: What is the best Java email address validation method?
If you really want to validate an email - Of course you need to get it confirmed:
see also: https://en.wikipedia.org/wiki/Closed-loop_authentication ...
Upvotes: 1
Reputation: 36
I think you made a mistake somewhere in your code, I tested the EmailValidator and it worked, both examples returned false:
import org.apache.commons.validator.routines.EmailValidator;
public class TestMail {
public static void main(String[] args) {
EmailValidator v = EmailValidator.getInstance();
System.out.println(v.isValid("[email protected]")); //false
System.out.println(v.isValid("random.bla@gmail")); //false
}
}
Using the dependency:
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.0</version>
</dependency>
Upvotes: 1