views:

397

answers:

4

Does anyone know what the regex used by the email validator in ASP.NET is? Pretty please.

+1  A: 

Here is the regex for the Internet Email Address using the RegularExpressionValidator in .NET

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

By the way if you put a RegularExpressionValidator on the page and go to the design view there is a ValidationExpression field that you can use to choose from a list of expressions provided by .NET. Once you choose the expression you want there is a Validation expression: textbox that holds the regex used for the validator

jmein
Is that how it's done in ASP.NET's email-validator? That'd match `_@_._`... I'd expected something more fancy.
Bart Kiers
@Bart check it out for yourself. I told you how I found it
jmein
I posted my comment when you only posted your regex and nothing more, so no, you didn't tell me how you found it. Besides, now that I read the rest of your post, I (being someone without any .NET experience and no means of testing it) am not able to go to the documentation you might be trying to point to. No matter, I was just a bit surprised that such a naive regex is used. I have no interest in checking it out myself.
Bart Kiers
Besides, validating e-mail addresses is just a waste of time, IMO.
Bart Kiers
Validating email addresses on the form is never a waste of time. You can still use it in conjunction with other checks.
IrishChieftain
Thanks for telling me how to find it!
JamesBrownIsDead
Well IrishChieftain, it seems we have a different opinion. Note the 'IMO' after my statement. Something that should also belong after yours... IMO. :)
Bart Kiers
IMHO.......... ;-)
IrishChieftain
Touche IrishChieftain! :)
Bart Kiers
+3  A: 

E-mail addresses are very difficult to verify correctly with a mere regex. Here is a pretty scary regex that supposedly implements RFC822, chapter 6, the specification of valid e-mail addresses.

Not really an answer, but maybe related to what you're trying to accomplish.

Thomas
+1 for epic regex link
RandomNoob
+2  A: 

I don't validate email address format anymore (Ok I check to make sure there is an at sign and a period after that). The reason for this is what says the correctly formatted address is even their email? You should be sending them an email and asking them to click a link or verify a code. This is the only real way to validate an email address is valid and that a person is actually able to recieve email.

Bob
Couldn't agree more! +1
Bart Kiers
A: 

For regex, I first look at this web site: RegExLib.com

joerage