如何使用正则表达式验证只有两个小数点后位数限制 [英] how to limit only two digits after decimal point using Regex Validator

查看:682
本文介绍了如何使用正则表达式验证只有两个小数点后位数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的REG-EX验证器来验证一个文本框为小数点后只接受两位数字。

I am using the following REG-EX validator to validate a text box for accepting only two digits after a decimal point .

<asp:RegularExpressionValidator Display="Dynamic" ID="regexp" runat="server" ControlToValidate="regexptest" ValidationGroup="regexptest" ValidationExpression="^\d+(\.\d\d)?$">

但我能小数点后输入两个以上的数值。

But I am able to enter more than two values after decimal point.

推荐答案

试试这个:

<asp:RegularExpressionValidator Display="Dynamic" ID="regexp" runat="server" 
     ControlToValidate="regexptest" ValidationGroup="regexptest" 
     ValidationExpression="^\d+(\.\d{1,2})?$">

这篇关于如何使用正则表达式验证只有两个小数点后位数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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