验证textbox的text 只能是数字或小数
用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+)(\.\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+)(\.\d+)?$">
</asp:RegularExpressionValidator>
<asp:Button ID="btnTest" runat="server" Text="测试" />
posted on 2010-01-26 14:23 xufeng001 阅读(1078) 评论(0) 编辑 收藏 举报