-3

I was looking for a very simple email validation. It just have to have an @ symbol and a period in the email. I want to accept for my string that will come in as a parameter.

Does anyone know of any easy email validations?

Jason C
  • 38,729
  • 14
  • 126
  • 182
user3457789
  • 21
  • 1
  • 2
  • 12

1 Answers1

2

The easiest way to do this is using InternetAddress from JavaMail. Just do new InternetAddress(email).validate() and it will throw an AddressException if it's invalid.

Matt
  • 637
  • 3
  • 10
  • It's not easy for me to test right now, but has the behavior changed since http://stackoverflow.com/a/5931718/616460 where it would (according to the comments there, which may be incorrect?) accept e.g. "abc" as a valid email? – Jason C Apr 01 '14 at 03:18
  • 1
    It actually is a bit permissive. For instance, the email `root@localhost` would be a valid email address. You might want to add domain name filters in production, though. – Matt Apr 01 '14 at 22:41