PatternBuilder: Example 1 - RegularExpressionValidator


Webbrowser

example1.jpg

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">

    <title>Esferatec.Text.RegularExpressions</title>

</head>

<body>

    <form id="frmExample" runat="server">
    
    <asp:Label ID="lblInput" runat="server" Text="Enter 5 digits:"></asp:Label>
    
    <asp:Label ID="lblPattern" runat="server" Text=""></asp:Label><br />
    
    <asp:TextBox ID="txtInput" runat="server"></asp:TextBox><br />

    <asp:RegularExpressionValidator ID="revInput" runat="server" 
    ErrorMessage="Please enter exactly 5 digits." ControlToValidate="txtInput">
    </asp:RegularExpressionValidator><br />

    <asp:Button ID="Button1" runat="server" Text="Validate" />

    </form>

</body>

</html>

Default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Esferatec.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PatternBuilder strPattern = new PatternBuilder();

        strPattern.AddDigitCharacter(PatternQuantifiers.Exactly,5,false);

        revInput.ValidationExpression = strPattern.Expression;

        lblPattern.Text = strPattern.Expression;
    }
}


Last edited Apr 18, 2010 at 7:26 PM by esferatec, version 16

Comments

No comments yet.