views:

46

answers:

3

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  A: 

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)

Strelok
Exactly what I just did too! I would go with some sort of standard for your Regex -- likely found in one of the 50 odd results you looked at.
Chris Missal
Thanks a ton guys! Just forgot reflector still existed and MS didnt obfuscate its code like other API vendors do. :)
Vaibhav
A: 

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!

Vaibhav
A: 

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

svick