如何限制用户在C#(WPF)的文本框中输入多个小数点 [英] How to restrict user from entering multiple decimal points in the text box in C#(WPF)

查看:372
本文介绍了如何限制用户在C#(WPF)的文本框中输入多个小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框(计划小时),我输入的值如12.4或1.5等...所以现在当用户输入2 ...时,它不应该允许输入多个小数点。目前文本框只允许小数点后的数字,如1.5。



i设置文本框的最大长度= 4,以wpf为单位。

那么请有人能为我提供解决方案吗?

i have a text box(planned hours) where am entering values like 12.4 or 1.5 etc... so now when the user just enters 2..., it should not allow to enter more than one decimal point.And currently the textbox will allow only digit after the decimal point like 1.5.

i have set the max length of the text box =4 in wpf.
So please can anyone provide me a solution?

推荐答案

使用 RegEx [ ^ ]。



进一步信息,请参阅:

WPF文本框接受十进制数 [ ^ ]

十进制数正则表达式 [ ^ ]
Use RegEx[^].

For further information, please see:
WPF textbox to accept decimal numbers[^]
Decimal number regular expression[^]


这篇关于如何限制用户在C#(WPF)的文本框中输入多个小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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