2

How to validate the given email address is correct irrespective of the domain.

for an example if i give

someone@gmail.com

or

someone@yahoo.com

like wise if i give any address the system must be able to say the given address is present at the domain

Joe
  • 4,460
  • 19
  • 60
  • 106
  • 4
    There is no way to validate that a given email address is actually valid until you send an email (and possibly get a bounce). You can verify the format of the email address, but not the validity. – Tejs Sep 14 '11 at 06:53
  • Hi, a warning. You have multiple deleted/closed questions now, and if you get too many of those, in proportion to open questions, the site will automatically prohibit you from posting more questions. This is just a heads-up, but please consult [faq] and [ask] on what is a good question / what is on-topic for this site. Thanks. (if you want to get rid of this comment, just respond to it here and I'll remove them both) – Lasse V. Karlsen Oct 20 '11 at 10:31

1 Answers1

7

You cannot in general validate that a given address is valid for a domain, short of sending an email and checking for a bounce.

Back in the day some email servers supported that type of query, but spammers promptly abused it so the capability was removed long ago.

You can validate that a domain is a valid one by e.g. doing a DNS lookup and looking for at least one MX record (MX indicates not only that the domain is valid, but that there's a mail exchanger entered in DNS).

It's non-trivial to validate with certainty whether an input string conforms to the format of a valid email address. See this question for a detailed discussion.

UPDATE

There are a few validators out there in common use that may be helpful, although they do not correctly perform validation in all cases, e.g.

Apache Commons EmailValidator (docs state that it does not catch all cases, including does not check that the top level domain exists).

RegEx example from MSDN My own unit tests indicate that it gives both false negatives and false positives for valid (but certainly uncommon) email addresses.

The Wikipedia article on email addresses provides a great overview of valid email address format and provides references to the appropriate RFCs.

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553