1

how to validate this id in vb.det

"[email protected]" using=ValidationExpression="^[\w-]+@[\w-]+.(com|net|org|edu|mil)$ this above code will not accept this id but this is a valid one for example

<tr>
        <td align="right">
          <font face="Arial" size="2">Email Address:</font>
        </td>
        <td>
          <asp:TextBox ID="email" Width="200px" MaxLength="60" runat="server" />
        </td>
        <td>
          <asp:RequiredFieldValidator ID="emailReqVal" ControlToValidate="email" ErrorMessage="Email. "
            Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
        *
          </asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator ID="emailRegexVal" ControlToValidate="email" ErrorMessage="Email. "
            Display="Static" ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
            Font-Names="Arial" Font-Size="11" runat="server">
        Not a valid e-mail address.  Must follow [email protected].
          </asp:RegularExpressionValidator>
        </td>
      </tr>

2 Answers 2

1
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
Sign up to request clarification or add additional context in comments.

Comments

1

The "." in the address is not part of the allowed characters specified by [\w-].

Try this instead: ^[\w.-]+@[\w.-]+\.(com|net|org|edu|mil)$

You should also escape the last "." since this would match any single character in regex, not necessarily a dot. Escaping it treats it as a literal dot as shown above.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.