文本框仅接受值中只有一个小数的浮点值 [英] Textbox that accepts only floating values with only one decimal in the value
问题描述
任何人都可以帮助我生成只有可接受浮动值的正则表达式,其中只能在值内添加一个小数
Ex: -
12.5 -------------允许输入
12.5。 -------------不允许输入第二个十进制数
12 -------------允许没有任何小数>
.12 -------------首先允许小数
12. -------------它也是好的允许
我有一个接受浮动值的正则表达式,即: -
正则表达式正则表达式=新正则表达式([^ 0-9。] +);
但问题在于你可以输入多个小数。
任何解决方案.....
先谢谢
Hi,
Can any one help me in generating the regex for only acceptable floating values where one can only able to add one decimal inside value
For Ex:-
12.5 -------------Allowed to type
12.5. -------------Don't allowed to type second decimal
12 -------------Allowed without any decimal
.12 -------------Allowed decimal in first place
12. -------------It's also ok to allow
I have one regex which accepts floating values i.e :-
Regex regex = new Regex("[^0-9.]+");
But the problem in it is that you can enter more than one decimal.
Any Solution.....
Thanks In Advance
推荐答案
我认为这个表达式会这样做:
\d * \。?\\\?
I think this expression will do it:
\d*\.?\d?
这篇关于文本框仅接受值中只有一个小数的浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!