Making sure the text-box value is an e-mail address : RegularExpressionValidator « Validation « ASP.NET Tutorial






<%@ Page Language="VB" %>
<script runat="server">

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
       Label1.Text = "Passwords match"
    End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>CompareFieldValidator</title>
</head>
<body>
    <form id="Form1" runat="server">
        Email:
        <asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                                        Runat="server" 
                                        ControlToValidate="TextBox1"
                                        ErrorMessage="You must enter an email address"
                                        ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
        </asp:RegularExpressionValidator>
        
            <asp:Button ID="Button1" OnClick="Button1_Click" 
             Runat="server" Text="Login"></asp:Button>
        
        
            <asp:Label ID="Label1" Runat="server"></asp:Label>
        
    </form>
</body>
</html>








8.10.RegularExpressionValidator
8.10.1.Making sure the text-box value is an e-mail address
8.10.2.Validate phone number
8.10.3.Validate email
8.10.4.Validate URL
8.10.5.Validate Name
8.10.6.Validate Zip code