...and here I was trying to figure out how to validate multiple email addresses separated by a comma inside a textbox. Could not really find much help online on Regular Expression at first, but then learned about JScript Regular Expressions versus .NET
RegEx and how JS RegEx is a subset of .NET RegEx, therefore most times you are better off using jScript on validators. Here is a link:
http://msdn2.microsoft.com/en-us/library/eahwtc9e(VS.80).aspx'">http://msdn2.microsoft.com/en-us/library/eahwtc9e(VS.80).aspx
I then learned here http://msdn2.microsoft.com/en-us/library/3206d374(VS.80).aspx">
http://msdn2.microsoft.com/en-us/library/3206d374(VS.80).aspx a little more about the syntax of RegEx (and remembered I knew all this stuff from my asp 3.0 previous life) and came up with this:
"((\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*([,])*)*"
it is the built-in RegEx for emails, plus a clause allowing for an optional comma "([,])*". I also wrapped the whole thing on "(...)*" to allow for multiple occurrences.
Next thing I will do is make sure only once comma is accept4d instead of the "zero or many" criteria of "*", and will also (try to) find a way to not having a comma at the end without a valid email after it.
See ya!
-
-
I've seen other characters on the LHS as well... & jumps out at me, but there are likely others.
The LHS of an email address isn't nearly as constrained as the RHS. -
In fact, it's nearly impossible to validate e-mail addresses using a RegEx. For example, if quoted, the LHS of an e-mail address can contain literally anything. "William, Kempf"@someserver.com is a valid e-mail address, for example. If you search Google carefully, you'll find numerous attempts, almost all fail. I've seen one example from a Perl RegEx book that claims to be fully correct, but the RegEx is nearly a page long and totally unreadable. It's also likely to be horribly slow. If you insist on validating e-mails (I don't recommend it) then I'd suggest rolling a proper parser and not using RegEx.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.