如何编写一个允许数字,逗号和点的正则表达式(如2,010.00) [英] How to write a regular expression which allows numbers and comma and dot (like 2,010.00)

查看:141
本文介绍了如何编写一个允许数字,逗号和点的正则表达式(如2,010.00)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写一个允许数字和逗号的正则表达式

基本上,用户可以使用逗号和小数点输入金额,例如
@ 20.22或2,010.00

允许数字的表达式就是这个,但是现在如何修改表达式以满足要求.
正则表达式m =新的正则表达式("^ [0-9]");


请提前告知我所做的更改........

I need to write a regular expression which allows numbers and Comma

Basically user can enter amount with comma and dot like
@20.22 or 2,010.00

Expression which allows numbers is this but now how to modify the expression to satisfy the requirement.
Regex m = new Regex("^[0-9]");


Please let me know the changes for this,thanks in advance.....

推荐答案

尝试使用以下工具:
Regexp编辑器 [ ^ ]
RegexLib [ ^ ]

以所需的方式形成正则表达式.试试吧.
Try tools like:
Regexp Editor[^]
RegexLib[^]

Form the regular expressions the way you want. Try it.


它会像这样:
It would go something like this:
^(((([0-9]{1,3},)([0-9]{3},)*[0-9]{3})|[0-9]{1,3})(\.[0-9]+)?)



如果要排除前导零,则必须对其进行一些修改.如果您确实想这样做,我建议您采纳Sandeep的建议,并考虑使用免费提供的一些有用工具自己构建它.


You''d have to modify that a bit if you want to exclude leading zeros. If you do want to do that, I recommend you take Sandeep''s suggestion and look into constructing it yourself using some of the useful tools freely available to you.


这篇关于如何编写一个允许数字,逗号和点的正则表达式(如2,010.00)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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