简体   繁体   English

如何验证ASP.Net TextBox应该允许带三个小数位的负或正十进制值?

[英]How to validate a ASP.Net TextBox which should allow negative or positive decimal value with three decimal places?

I have a textbox which should allow user to enter only positive or negative decimal number with three decimal places. 我有一个文本框,应允许用户仅输入带三个小数位的正或负十进制数。 For Example: 73.345 or -2345.345 or -32.34. 例如:73.345或-2345.345或-32.34。 something like that. 这样的事情。 How to set the validation for this? 如何为此设置验证?

Whether validation is by either using Validation Controls or by JavaScript. 验证是通过使用验证控件还是通过JavaScript。 Any suggestions please. 有任何建议请。

I would use a RegularExpressionValidator to do the work for you. 我将使用RegularExpressionValidator为您完成这项工作。 Your regular expression, assuming the decimal point and digits immediately following are options, is then: 假设紧随其后的小数点和数字为正则表达式,则为:

-?\d+(\.\d{1,3})?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM