Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
How can we prevent invalid domain from being entered into the email address field?
example:
test@gmale.com
Posted 7-Oct-12 20:24pm
Comments
Sergey Alexandrovich Kryukov at 8-Oct-12 3:26am
   
What makes you think that this domain is invalid? It could be a valid domain used for mail, for example...
--SA
Mannava Siva Aditya at 8-Oct-12 3:37am
   
If not this try to enter an invalid mail address with invalid domain.
Sergey Alexandrovich Kryukov at 8-Oct-12 13:34pm
   
Do you mean "invalid" as not represented by DNS. Is so, try to resolve IP by domain name using DNS. After all, when you obtain it, ping it. I think this is the most guarantee you can possibly have.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You cannot prevent tha. You can check the text entered by e.g. trying to resolve an IP address for that. But it still be actually invalid: many domains were registered just to take money from those who want to use it - you can see that when you enter an address in the browser and a typo happens.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Please see my comment to the question. First, you need to try to resolve IPs via DNS using the domain name using the class System.Net.Dns:
http://msdn.microsoft.com/en-us/library/system.net.dns.gethostaddresses.aspx[^].
 
You can also ping the IPs using the class System.Net.NetworkInformation.Ping:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx[^].
 
You can find some code sample here:
http://stackoverflow.com/questions/3689728/ping-a-hostname-on-the-network[^].
 
The successful ping does not proof the domain is valid as a mail delivery agent; and the failed ping does not proof the e-mail is not served at this domain, as the domain could be out of service for a short period of time. It just give you an extra criterion for validity, which is itself does not have strictly 100% validity, which is probably impossible with the present day mail delivery system we all use.
 
—SA
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid