如何使文本框接受小数点前最多两位数,然后是一个必需的小数点,然后是C#小数点后的一位数 [英] How to make textbox accept max two digits before decimal point, then a mandatory decimal point and then one single digit after the decimal point in C#

查看:116
本文介绍了如何使文本框接受小数点前最多两位数,然后是一个必需的小数点,然后是C#小数点后的一位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文本框,允许用户输入小时数。

它只允许数字和小数值。

现在如何允许用户输入最多两位数在十进制之前,然后是小数点,然后是一位数。







ex:

1.2或12.5或仅12 --->有效值





但是当用户尝试输入12 ..或1211或122等值时.----->在有效值中,文本框不应该允许..



并且用户不能输入多个小数点。

I have text box which allows user to enters hours.
It will allow only numeric and decimal values.
So now how to allow user enters max of two digits before decimal, followed by decimal point, and then followed by single digit.



ex:
1.2 or 12.5 or just 12 ---> valid values


but when the user tries to enter values like 12.. or 1211 or 122. ----->In valid values, the text box should not allow..

And user should not be able to enter more than one decimal point .

推荐答案

你可以做到......但是NumericUpDown是一个更好的解决方案,甚至是MaskedTextBox。

(对于网站,有一个AJAX扩展器: MaskedEdit [ ^ ]也将这样做。)
You can do it...but a NumericUpDown is a better solution, or even a MaskedTextBox.
(For websites, there is an AJAX extender: MaskedEdit[^] which will do it as well.)


这篇关于如何使文本框接受小数点前最多两位数,然后是一个必需的小数点,然后是C#小数点后的一位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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