验证电子邮件地址 [英] Validate an email address

查看:123
本文介绍了验证电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VB.NET进行电子邮件验证?

How do you do email validation with VB.NET?

推荐答案

如果您只想验证字符串是否为正确的电子邮件格式,请使用正则表达式.有关示例,请参见此处:

http://msdn.microsoft.com/en-us/library/01escwtf.aspx [ ^ ]

如果要验证地址是否有效且有效,则没有完美的方法.您可以从特定的地址发送测试电子邮件,然后检查新邮件中所使用的发件人地址,如果收到退回电子邮件,请解析正文以弄清楚退回是否针对您发送的电子邮件.这假定目标主机已配置为发送回退邮件.

在更简单的级别上,您可以解析域的MX记录,然后查看是否存在.至少可以保证一个有效的主机.当然,这不会为您验证用户名.

然后,还有一些电子邮件服务器被配置为将电子邮件吞没给不存在的用户(这是一种反垃圾邮件方法,可以防止垃圾邮件发送者检测到错误的地址或真实的地址).确实,您对此无能为力.
If you just want to verify that a string is in proper email format, use regular expressions. For an example, see here:

http://msdn.microsoft.com/en-us/library/01escwtf.aspx[^]

If you want to verify whether the address is valid and active, there''s no perfect way to do this. You could send a test email from a specific address, and then check new mail for the from-address that you used, and if you get a bounce email, parse the body to figure out if the bounce is for the email you sent. This assumes that the target host is configured to send back bounce messages.

At a simpler level, you could resolve the MX record for the domain and see if exists. That at least guarantees a valid host. Of course this won''t verify the username for you.

And then there are email servers that are configured to swallow emails to non-existent users (this is an anti-spam method to prevent spammers from detecting bad addresses or real ones). Not much you can do about those really.


正则表达式将是最佳解决方案.

如果要进行简单测试以查看电子邮件是否属于特定域,则可以执行以下操作:

IF emailAddress.EndsWith("@ yourdomain.com")

其中emailAddress是包含...电子邮件地址的字符串.

-Richard
A regular expression would be the best solution.

If you want to do a simple test to see if an email is part of a specific domain, you could simply do the following:

IF emailAddress.EndsWith("@yourdomain.com")

where emailAddress is a string containing...the email address.

-Richard


首先在浏览器的地址栏中输入"google".
Start by typing "google" in your browser''s address bar.


这篇关于验证电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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