Asp.net如何在textbox keypress事件中限制小数点前后的数字长度 [英] Asp.net How to limit number length before and after the decimal point in textbox keypress event

查看:73
本文介绍了Asp.net如何在textbox keypress事件中限制小数点前后的数字长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个带文本框的Gridview。如何限制textbox按键事件中小数点前后的数字长度。我希望小数点前最多6个数字,点后2个数字。如何用javascript / jQuery解决它。



请帮帮我..



提前致谢。 。



Vineetha



I have a Gridview with a textbox. How to limit number length before and after the decimal point in textbox keypress event . I want maximum 6 numbers before the decimal point and two number after the point . How to solve it with javascript/JQuery.

Please help me..

Thanks in advance..

Vineetha

推荐答案

我认为你应该使用正则表达式,

ie



I think you should use Regular Expression,
i.e

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator

        id="RegularExpressionValidator1"

        runat="server"

        ControlToValidate="TextBox1"

        ValidationExpression="^[0-9]{1,6}(\.[0-9]{0,2})?




ErrorMessage = 无效数字 / > 无效的数字< ; / asp:RegularExpressionValidator >
" ErrorMessage="Invalid Number" />Invalid number</asp:RegularExpressionValidator>


这篇关于Asp.net如何在textbox keypress事件中限制小数点前后的数字长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆