Is RegEx used by System.Net.Mail.MailAddress

做~自己de王妃 提交于 2019-12-12 06:23:32

问题


I have been trying to find a good RegEx for email validation.

I have already gone through Comparing E-mail Address Validating Regular Expressions and that didn't suffice all my validation needs. I have Google/Bing(ed) and scan the top 50 odd results including regular expressions info article and other stuff.

So finally i used the System.Net.Mail.MailAddress class to validate my email address. Since, if this fails, my email won't get sent to the user.

I want to customize the validation as used by the constructor of the class.

So how do I go ahead and get the validation/RegEx that the MailAddress class is using?


回答1:


No it does not use a RegEx, but rather a complicated process that would take way too long to explain here. How do I know? I looked at the implementation using the .NET Reflector. And so can you :D

http://www.red-gate.com/products/reflector/ (it's free)




回答2:


Thanks Reflector... forgot you were still free!

Reflected the System.Net.Mail.MailAddress...

Found that it used a void ParseValue(string address)

and void GetParts(string address) methods to primary check the mail address format.

//Edited

Surprised, no RegEx was involved!




回答3:


According to the Reflector, the class doesn't use regular expressions at all.



来源:https://stackoverflow.com/questions/3766668/is-regex-used-by-system-net-mail-mailaddress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!