What's a C# regular expression that'll validate currency, float or integer?

前端 未结 8 2426
闹比i
闹比i 2020-12-06 12:21

What is a regular expression suitable for C# that\'ll validate a number if it matches the following?

 $1,000,000.150
 $10000000.199
 $10000 
 1,         


        
8条回答
  •  旧时难觅i
    2020-12-06 13:03

    I think I've found a problem with ssg's solution (or perhaps an MS bug!).

    Running this:

    float.TryParse("0,2",NumberStyles.Currency, CultureInfo.GetCultureInfo("en-US"), out num)
    

    Returns true. Surely "0,2" isn't a valid currency value?

提交回复
热议问题