需要正则表达式来验证货币值 [英] Need regular Expression To Validate Currency Value

查看:89
本文介绍了需要正则表达式来验证货币值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证货币值,如







































































它不应该接受

0.00
0.00000
000000000.00
等等任何帮助都会被批评...

解决方案

试试这个:
^([1-9] [0-9] {0,9} \\ \\ [0-9] {2} | 0 + \ [1-9] [0-9] |。。0 + \ [0-9] [1-9])


但是,我认为这种正则表达式的使用是不合适的。使用以下代码更有效:
string input =" 112312323.04" ;;
bool valid;
try
{
if( float.Parse(input)== 0)
throw new Exception();
valid = true;
}
catch
{
valid = false;
}

i want to validate currency value like

two digits after dot.

it should accept
10.00
12.13
112312323.04
0.50
123.13


and it should not accept

0.00
0.00000
000000000.00
and so on

any help would be appriciated...

解决方案

Try this one:
^([1-9][0-9]{0,9}\.[0-9]{2}|0+\.[1-9][0-9]|0+\.[0-9][1-9])



However, I think such regular expression usage is inexpediently. It is much more effective to use following code:
string input = "112312323.04";
bool valid;
try
{
    if(float.Parse(input) == 0)
        throw new Exception();
    valid = true;
}
catch
{
    valid = false;
}


这篇关于需要正则表达式来验证货币值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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