RegularExpressionValidator for multiple emails

I’m validating a textbox for valid email with this:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
ControlToValidate="txtMailCustom"
Text="Invalid address"
ValidationExpression="^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]
{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$" runat="server" />

Now I want users to be able to put multiple email addresses , separated by a comma and space.

How can I integrate that behaviour ?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try the expression below, which works for me:

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

The above code is for ,, separating e-mail addresses.

If you would like to use ; instead of ,, than replace , with ; at the end of the above expression.

Method 2

try this expression:

^(s*,?s*[0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[a-zA-Z]{2,9})+s*$

Method 3

I should do this: what it does is check for at least one mail, and for list of email before it with each a comma and possibly a space.

^(([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?), ?)*^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$

Use this if the space between each mail is required:

^(([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?), )*^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$

Note I just used your single mail checker as a base and didn’t really edit it.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x