Joe
Joe

Reputation: 4542

Validate email address irrespective of the domain

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

Upvotes: 2

Views: 472

Answers (1)

Eric J.
Eric J.

Reputation: 150198

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.

Upvotes: 7

Related Questions