我们如何防止将无效域输入到电子邮件地址字段? [英] How can we prevent invalid domain from being entered into the email address field?

查看:150
本文介绍了我们如何防止将无效域输入到电子邮件地址字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止将无效域输入到电子邮件地址字段中?
例如:
test@gmale.com

How can we prevent invalid domain from being entered into the email address field?
example:
test@gmale.com

推荐答案

您无法阻止tha.您可以检查输入的文字,例如尝试为此解析IP地址.但这实际上仍然是无效的:许多域名只是为了从想要使用它的人那里赚钱而注册的-您可以看到,当您在浏览器中输入地址并出现输入错误时.
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.


请参阅我对问题的评论.首先,您需要尝试使用类System.Net.Dns:
的域名通过DNS解析IP. http://msdn.microsoft.com/en-us/library/system. net.dns.gethostaddresses.aspx [ ^ ].

您也可以使用System.Net.NetworkInformation.Ping类对IP进行ping操作:
http://msdn.microsoft.com/en-us/library/system. net.networkinformation.ping.aspx [ ^ ].

您可以在此处找到一些代码示例:
> http://stackoverflow.com/questions/3689728/ping-a-hostname-on-网络 [ ^ ].

成功ping不能证明该域作为邮件传递代理有效.并且失败的ping不能证明该域不提供电子邮件,因为该域可能会在短时间内停止服务.它只是为您提供了一个额外的有效性标准,该标准本身并不严格地具有100%的有效性,而对于当今我们都使用的邮件传递系统来说,这可能是不可能的.

—SA
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


这篇关于我们如何防止将无效域输入到电子邮件地址字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆