2

After writing this, also while entering email it is showing an error message and it is working fine. I don't know whats going on. Any one please explain once. Thanks in advance

<asp:RequiredFieldValidator ID="Txt5" runat="server" ControlToValidate="TextBox5" ValidationGroup="abc" ErrorMessage="*"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="Txt05" runat="server" ControlToValidate = "TextBox5" Display ="Dynamic" ValidationExpression="^\w+([-+.']\w+)*@domain.com$" ErrorMessage="Please enter valid email address.."></asp:RegularExpressionValidator>
apxcode
  • 7,696
  • 7
  • 30
  • 41
chrish549
  • 91
  • 1
  • 3
  • 11

2 Answers2

4

Please use this one as your regular expression:

ValidationExpression="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@
(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"

For further clarification, on how this works, please look here.

As it is now, your regular expression matces only email addresses with domain equal to domain and .com extension. Certainly, that's a problem, since xzxzx@yahoo.gr is a valid email address and your reg exp will not evaluate it as a valid one. (xzxzx would be some name)

Christos
  • 53,228
  • 8
  • 76
  • 108
0

According to your expression, it expects @domain.com at the end of each email address.. Hence, 'something@domain.com' would not show any error message.. Try the expression as mentioned in the post Using a regular expression to validate an email address

Community
  • 1
  • 1
Mrudang Vora
  • 255
  • 1
  • 5
  • 20