只包含在C#中的数字和逗号或点 [英] Contains only digit and comma or dot in C#

查看:402
本文介绍了只包含在C#中的数字和逗号或点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查相匹配的字符串1逗号或1个点,只有数字必须包含
u能提供正则表达式的一些例子吗?谢谢

I need to check string on matches 1 comma or 1 dot and only numbers must contains Can u provide some example on regexp?Thank you

推荐答案

下面是最简单的正则表达式:

Here's the simplest regex:

^\d*[,.]\d*$

然而,这只是没有数字。如果你之前或逗号或点后至少需要一个数字,我觉得这是它:

However, this will succeed for just . or , with no digits. If you require at least one digit either before or after the comma or dot, I think this is it:

^(\d+[,.]\d*|\d*[,.]\d+)$

如果逗号或圆点是可选的,而不是需要,添加 [。]

If the comma or dot is optional rather than required, add ? after [,.].

这篇关于只包含在C#中的数字和逗号或点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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