Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Trying to validate EmailID with RE. It validates emailID only except domain name added after "dot".

i.e. if I put emailID info@abc.2323, this still works, even though I have entered wrong/invalid domain.

How can I validate email id against valid domains exist.

Thanks in advance...
Posted
Updated 12-Sep-22 17:48pm

You could ping the domain to see if it exists, but it is possible to have an email address with a domain that is not publicly visible.

The best way is to let the user add anything they like but send an authentication email to the account to confirm it.

This will only work if the email is there own.

You could also flag bad email addresses after you have received a address-not-found response.

To be sure, there is no 100% silver bullet. The best method depends on your specific needs
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Aug-15 4:12am    
Makes sense, 5ed.
See also Solution 2.
—SA
In addition to Solution 1: see also https://en.wikipedia.org/wiki/Email_tracking[^].

The bottom line is: this all works only for mail agents which voluntarily agree to support one or another way of tracking. So, in practice, you can do it only withing your organization or perhaps with some of your business partners, based on mutual agreements. Typically, no method are really supported, because it would increase the level of spamming.

—SA
 
Share this answer
 
You can only validate the text is of the something something@something.something, you can't verify if the email itself is valid or the domains are valid. You're better off not doing any validation on the email at all, you'll only end up rejecting addresses that are genuine because they don't match your regex. The only way to verify the address is valid is to send it an email with a validation link the user needs to click on to say the address is real.
 
Share this answer
 
C#
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
 
Share this answer
 
Thanks for help from all guys...
Overall conclusion shared of not validating domain name seems to be correct.
Will share this aspect with user and see if we can skip this part. Else will ask user to provide list of domains to be allowed and validate them...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900