1

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?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Vaibhav
  • 1,156
  • 2
  • 12
  • 27

3 Answers3

3

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
  • 50,229
  • 9
  • 102
  • 115
  • 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 Sep 22 '10 at 06:10
  • Thanks a ton guys! Just forgot reflector still existed and MS didnt obfuscate its code like other API vendors do. :) – Vaibhav Sep 22 '10 at 06:12
  • Here's the source code use for parsing http://referencesource.microsoft.com/#System/net/System/Net/mail/MailAddressParser.cs – stefann May 25 '17 at 06:55
1

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
  • 1,156
  • 2
  • 12
  • 27
  • Here's the source code use for parsing http://referencesource.microsoft.com/#System/net/System/Net/mail/MailAddressParser.cs – stefann May 25 '17 at 06:56
0

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

svick
  • 236,525
  • 50
  • 385
  • 514