C#RegEx十进制数 [英] C# RegEx for decimal number
本文介绍了C#RegEx十进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为文本框创建一个正则表达式,该表达式只能只允许数字或小数.例如,我应该能够同时输入10和10,350.
I'm trying to make a Regular expression for a textbox which should only allow either only digits or decimals. For example, I should be able to enter both 10 and 10,350.
我将使用的十进制分隔符是,",并且十进制长度不需要限制.
The decimal seperator I'll use is "," and the decimal length don't need a limit.
任何人都知道我如何制作这样的RegEx吗?
Anyone knows how I can make such a RegEx?
推荐答案
我也想使用 decimal.TryParse()
,但是如果您确实需要RegEx,那么应该可以使用以下方法:(\ d +(,\ d *)?)
I'd go for decimal.TryParse()
too, but if you really need a RegEx then something like this should work: (\d+(,\d*)?)
这篇关于C#RegEx十进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文