开发者

C# RegEx for decimal number

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.

Anyone knows how I can make such a RegEx?


I'd go for decimal.TryParse() too, but if you really need a RegEx then something like this should work: (\d+(,\d*)?)


Just use decimal.TryParse or double.TryParse.


if you will use it in many place in your project you can make new TextBoxcontrol it accept just number and make ',' when even the '.' clicked, and you can make test on it when it lostfocus()


Here's your regex:

^[\d]+,?[\d]*$

check if it matches what's in your textbox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜