Can anyone correct the expression below to also not allow blank field?
<asp:RegularExpressionValidator ID="expEmail" runat="server" ControlToValidate="txtEmail" ErrorMessage="valid email address required" ValidationExpression="^([a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]){1,70}$"></asp:RegularExpressionValidator>
One of the solutions (not a best one) is to implement some regular expression:
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
Sample: [email protected]
But actually, it's very hard to write and maintain a good email validation regexp. You shouldn't trust 100% your regex. You can find several articles about that difficulty on the Internet:
Add a required field validator as well - I think the regex validator will only fire if there is text in the field to look at.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With