Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Regular Expression for multiple email validation using the RegularExpressionValidator control

Back to Forum: Tech Off
  • User profile image
    Mauricio Feijo

    ...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:'">

    I then learned here"> 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:


    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!

  • User profile image
    Matthew van Eerde

    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.

  • User profile image

    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" 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.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.