asp.net control validation email

ITsolutionWizard
ITsolutionWizard used Ask the Experts™
on
I use the following asp net email validator and it works fine until today I get an email (jsmiths@ca--homes.com).
And I want to ensure to accept this string '--'.

how can I do that with my current email validator?


<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="NewEmailAddressTextBox" CssClass="red bold"
            Display="Dynamic" ErrorMessage="*"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
            ValidationGroup="AddNewEmail"></asp:RegularExpressionValidator>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Better to do this...

1) Split out user + host parts.

2) Run many regexp patterns against each separately.

Tip: Trying to create a validator with a single regular expression is near impossible to debug or extend.

Author

Commented:
I guess how to create ValidationExpression to accept -- and @ will be helpful.
I found the solution using expression: ^([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})(\]?)$

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial