RegularExpressionValidator compares value against a regular expression : Regular Expression « Validation « ASP.NET Tutorial






<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show RegularExpressionValidator</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblEmail"
        Text="Email Address:"
        AssociatedControlID="txtEmail"
        Runat="server" />
    <asp:TextBox
        id="txtEmail"
        Runat="server" />
    <asp:RegularExpressionValidator
        id="regEmail"
        ControlToValidate="txtEmail"
        Text="(Invalid email)"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        Runat="server" />

    <br /><br />

    <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" />

    </div>
    </form>
</body>
</html>








8.9.Regular Expression
8.9.1.The predefined character classes
8.9.2.quantifiers used to create patterns that match a variable number of characters at a certain position in the string
8.9.3.Metacharacters for Matching Single Characters
8.9.4.Metacharacters for Matching Types of Characters
8.9.5.Quantifiers
8.9.6.Commonly Used Regular Expressions
8.9.7.RegularExpressionValidator compares value against a regular expression
8.9.8.Regular Expression based validation (C#)
8.9.9.Use asp:RegularExpressionValidator to check the zip code
8.9.10.Use asp:RegularExpressionValidator to check the email address
8.9.11.Use Regular expression to validate a Phone number