ASP.NET中用于十进制验证的正则表达式

时间:2022-01-23 15:54:19

I am currently attempting to use a regular expression validator control in ASP.NET to validate a textbox that will be used for input for a database that accepts a decimal value.

我目前正在尝试在ASP.NET中使用正则表达式验证器控件来验证将用于接受十进制值的数据库的输入的文本框。

I want this value to accept up to 18 digits before the decimal, and 1 digit after. With the decimal point and the digit after it being optional

我希望这个值在小数点前最多接受18位数,之后接受1位数。带小数点和可选后的数字

For example all the following would be accepted

例如,以下所有内容都将被接受

  • 1.0
  • 100.1
  • 123456789123456789.2
  • 123456789123456789

But these examples would not

但这些例子不会

  • 1.01
  • 1234567891234567891
  • 1234567891234567891.0

I am currently using this as my regular expression, however it seems to be accepting things that are more than 18 digits before the decimal point.

我目前正在使用它作为我的正则表达式,但它似乎接受小数点前超过18位的东西。

^(\d{1,18})+(\.\d{1})?$

Anyone know what I did wrong here?

谁知道我在这里做错了什么?

Thanks for your help in advanced!

感谢您的高级帮助!

1 个解决方案

#1


1  

Drop the '+'

放下'+'

^(\d{1,18})(.\d{1})?$

#1


1  

Drop the '+'

放下'+'

^(\d{1,18})(.\d{1})?$