验证有效的电子邮件格式 [英] Verity the valid Email format

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

问题描述

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

我们使用上面的URL中的代码进行验证.现在,在所有情况下都可以正常工作,但只有以下两种格式显示有效.

we are validate using code in above url. Now working fine all scenarios but only bellow two format are showing valid.

test.crs@example-.com
test.crs@example_.com

test.crs@example-.com
test.crs@example_.com

使用以下网址,我们可以找到有效或无效的电子邮件ID格式

we can find Email id format valid or not, Using bellow url

http://sqa.fyicenter.com/Online_Test_Tools/Email_Address_Format_Validator.php

您能否提供有效的正则表达式!

Can you give a valid Regular Expression!


感谢与问候,Swaroop

Thanks & Regards, Swaroop

推荐答案

您链接的示例使用RE来验证电子邮件.您有此要求吗? MailAddress类已经按照RFC标准进行了验证.如果需要这种功能,我倾向于使用它来验证电子邮件格式 与一样 其他.这样可以减少我必须维护的代码,并确保即使将来标准不断发展,我的代码也可以正常工作.它还消除了MailAddress(通常用于发送电子邮件的地址)不会失败的可能性 我的RE认为有效的内容. MailAddress做RE不能做的另一件事是长度验证.电子邮件地址的RFC对子域各部分的长度设置了上限.这可能很难做到(或者可能 甚至不可能),因为RE不是针对此类事情而设计的. RE的.NET版本与纯"版本相比确实很健壮. RE,但我仍然认为如果没有在顶部添加一些自定义验证,它就不能完全处理验证.基本上 MailAddress已经完成的所有工作.

The example you linked to is using RE to validate the email.  Do you have this requirement?  The MailAddress class already does validation against the RFC standard.  I tend to use it to validate email formats if I need that kind of functionailty as do others.  It cuts down on code I have to maintain and ensures that my code works even if the standard evolves in the future.  It also eliminates the off chance that MailAddress (which is what you'll generally use for sending emails) doesn't fail something that my RE considers valid.  Another thing that MailAddress does that RE cannot is length validation.  The RFC for email addresses puts an upper limit on the length of each part of a subdomain.  This can be hard to do (or possibly not even possible) because RE isn't designed for that kind of thing.  The .NET version of RE is really robust compared to "pure" RE but I still don't think it can completely handle the validation without some custom validation added on top.  Basically all that MailAddress already does.

您发布的2个电子邮件地址无效.您链接到的URL将其标识为无效,但MailAddress认为它是有效的.根据我对 上面的地址 RFC语法有效,因为子域部分在字符集中仅包含有效字符.

The 2 email addresses you posted are not valid.  The URL you linked to identifies it as invalid but MailAddress considers it valid.  Based upon my interpretation of the RFC grammar the above addresses are valid because the subdomain portions contain only valid chars in the charset.

迈克尔·泰勒
http://msmvps.com/blogs/p3net

Michael Taylor
http://msmvps.com/blogs/p3net


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

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