asp.net验证控件
3个回答
展开全部
用RequiredFieldValidator非空验证控件和RangeValidator范围验证控件搭配
或者用RequiredFieldValidator非空验证控件和RegularExpressionValidator正则表达式验证控件搭配都可以(我写另一种)
但是要记住这两种搭配中都少不了非空验证控件哦
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="rqvNumber"
runat="server"
ControlToValidate="txtNumber"
ErrorMessage="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="rgvNumber"
runat="server"
ControlToValidate="txtNumber"
ErrorMessage="请输入数字"
ValidationExpression="\d+">
</asp:RegularExpressionValidator>
<asp:Button ID="btnTest" runat="server" Text="测试" />
或者用RequiredFieldValidator非空验证控件和RegularExpressionValidator正则表达式验证控件搭配都可以(我写另一种)
但是要记住这两种搭配中都少不了非空验证控件哦
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="rqvNumber"
runat="server"
ControlToValidate="txtNumber"
ErrorMessage="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="rgvNumber"
runat="server"
ControlToValidate="txtNumber"
ErrorMessage="请输入数字"
ValidationExpression="\d+">
</asp:RegularExpressionValidator>
<asp:Button ID="btnTest" runat="server" Text="测试" />
展开全部
RequiredFieldValidator和RangeValidator
用法:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="不能为空"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox3" Display="Dynamic"
ErrorMessage="格式不对" MaximumValue="99999999" MinimumValue="0" Type="Double"></asp:RangeValidator>
用法:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="不能为空"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox3" Display="Dynamic"
ErrorMessage="格式不对" MaximumValue="99999999" MinimumValue="0" Type="Double"></asp:RangeValidator>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以具体看一下我也忘记了,可以指定正则表达式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询