tags:

views:

18

answers:

2

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>
+1  A: 

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.

Ahmad Mageed
thank u for ur reply my friend
+1  A: 
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
Pavanred
thanks a lot for ur kind reply thanks a lot