0

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 :

random@.com -> true
random.bla@gmail -> true

is there a better way to validate emails?

Rmahajan
  • 1,311
  • 1
  • 14
  • 23
MikasaAckerman
  • 531
  • 5
  • 17

3 Answers3

1

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("random@.com")); //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>
1

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 ...


xerx593
  • 12,237
  • 5
  • 33
  • 64
0

Apache common email validator valid when email address has & char but it is not true.

        assertFalse(EmailValidatorUtil.isValid("asdfasd&@hotmail.com"));
neoerol
  • 911
  • 1
  • 12
  • 18