1、RequiredFieldValidator 必填项,检查非空字符串(空格不算在内)
用户名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="不能为空" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
2、 CompareValidator 比较验证,比较密码是否一致
重复密码:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="两次密码不一致"
ControlToValidate="TextBox3" ControlToCompare="TextBox2">
</asp:CompareValidator>
3、 RangeValidator 范围验证
身高:<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="1111" ControlToValidate="TextBox4"
MaximumValue="3" MinimumValue="0" Type="Double"></asp:RangeValidator>
4、RegularExpressionValidator 通过正则验证
邮箱:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox5" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ErrorMessage="RegularExpressionValidator"></asp:RegularExpressionValidator>
5、CustomValidator 用户自定义控件
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ControlToValidate="要验证的控件ID"
ClientValidationFunction="客户端脚本验证方法" OnServerValidate="服务器端验证方法名">
</asp:CustomValidator>