|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Saturday, March 25, 2006The RegularExpressionValidator Control(Chapter3)The RegularExpressionValidator control is typically used to match an input pattern. As an example, let us assume that the value of hours-worked field must have one to three digits. In this case, we will add a RegularExpressionValidator to the txtHcontrol. In the RegularExpression property of the RegularExpressionValidator, we will specify a pattern /d{1,3}. This will force the system to raise an error if the user input is not one-to-three digits long.The output of this application is shown in Figure 3.52.
Figure 3.52 Using RegularExpressionValidator Controls Figure 3.53 Validator2.aspx <!—- Chapter3\Validator2.aspx —> <%@ Page Language="VB" Debug="true" %> <html><head</head><body> <form runat="server"><br> Enter Your Name: <asp:TextBox id="txtName" rows="1 " width="60" runat="server"/> <asp:RequiredFieldValidator id="validTxtName" runat="server" controlToValidate="txtName" errorMessage="Name must be entered" display="static"> </asp:RequiredFieldValidator></br> Hours worked? <asp:TextBox id="txtH" width ="40" runat="server" /> <asp:RequiredFieldValidator id="validTxtH" runat="server" controlToValidate="txtH" errorMessage="Hours must be entered" display="static"> </asp:RequiredFieldValidator> <asp:RegularExpressionValidator id="regvH" runat="server" display="static" controlToValidate="txtH" errorMessage="Hours must be 1-3 digits only" validationExpression="\d{1,3}"> </asp:RegularExpressionValidator></br> <asp:Button id="btnSubmit" runat="server" text="Submit" /> </form></body></html> |
0 Comments:
Post a Comment
<< Home