ASP.Net 验证控件 CompareValidator
CompareValidator
作用就是比较两个输入框所输入的值是否一致,常用来作为验证输入密码和确认密码的业务。
属性 | 描述 |
Operator | 比较操作符,可选值DataTypeCheck、Equal、GreaterThan、GreaterThanEqul、LessThan、LessThanEqual、NotEqual |
ValueToCompare | 所比较的运算符右边的值 |
ControlToCompare | 设定与另外一个控件进行比较 |
Type | 数据类型可选String、Integer、Double、Date、Currency |
1 <form id="form1" runat="server"> 2 <div> 3 <table border="1"> 4 <tr> 5 <td class="style1">Password</td> 6 <td class="style2"> 7 <asp:TextBox ID="txtPwd" runat="server" TextMode="Password"></asp:TextBox> 8 </td> 9 </tr> 10 <tr> 11 <td class="style1">Confirm Password</td> 12 <td class="style2"> 13 <asp:TextBox ID="txtConfirmPwd" runat="server" TextMode="Password"></asp:TextBox> 14 <asp:CompareValidator ID="CompareValidator1" runat="server" 15 ControlToCompare="txtPwd" ControlToValidate="txtConfirmPwd" 16 ErrorMessage="*Password not match" ForeColor="Red"></asp:CompareValidator> 17 </td> 18 </tr> 19 </table> 20 <asp:Button ID="btnSubmit" runat="server" Text="Submit" /> 21 </div> 22 </form>
与一个定值进行比较
1 <form id="form1" runat="server"> 2 <div> 3 <table border="1"> 4 <tr> 5 <td class="style3">Input value </td> 6 <td class="style4"> 7 <asp:TextBox ID="txtValue" runat="server" TextMode="Number"></asp:TextBox> 8 <asp:CompareValidator ID="CompareValidator1" runat="server" 9 ControlToValidate="txtValue" ErrorMessage="* Number is not greater than 100" 10 ForeColor="Red" Operator="GreaterThan" Type="Integer" ValueToCompare="100"></asp:CompareValidator> 11 </td> 12 </tr> 13 <tr> 14 <td class="style1"> 15 <asp:Button ID="btnSubmit" runat="server" Text="Submit" /> 16 </td> 17 <td class="style2"> </td> 18 </tr> 19 </table> 20 </div> 21 </form>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。