tags:

views:

319

answers:

4

i am using the follwoing regular expression

  (".+@.+\\.[a-z]+")

Bit it accepts #@#.com as a valid email.whats the pattere i shold use?

+1  A: 

Here's a web page that explains that better than I can: http://www.regular-expressions.info/email.html (EDIT: that appears to be a bit out of date since it refers to RFC 2822, which has been superseded by RFC 5322)

And another with an interesting take on the problem of validation: http://www.markussipila.info/pub/emailvalidator.php

Generally the best strategy for validating an email address is to just try sending mail to it.

David Zaslavsky
+1  A: 

Have a look at this article.

Bozhidar Batsov
A: 

You should use apache-commons email validator. You can get the jar file from here.

Here is a simple example of how to use it:

import org.apache.commons.validator.EmailValidator;

boolean isValidEmail = EmailValidator.getInstance().isValid(emailAddress);
CoolBeans
+1  A: 

If somebody wants to enter non-existent email address he'll do it whatever format validation you choose.

The only way to check that user owns email he entered is to send confirmation (or activation) link to that address and ask user to click it.

So don't try to make life of your users harder. Checking for presence of @ is good enough.

Konstantin Spirin