MikasaAckerman
MikasaAckerman

Reputation: 529

apache common validator returns false positive result

While using Apache common Email validator as below link:

https://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/EmailValidator.html

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

Answers (3)

neoerol
neoerol

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

xerx593
xerx593

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:

  • first do static validation (as good as you/your lib can)
  • then send an email:
    • with an identifying confirmation link, which recipient has to "click" (http get!).
  • write the according endpoint/servlet/controller (http get), which "completes validation".

see also: https://en.wikipedia.org/wiki/Closed-loop_authentication ...


Upvotes: 1

Paulo Martinelli
Paulo Martinelli

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

Related Questions