要求:通过验证的可以是带逗号的数字形式:如
4,123     
479,568,456.56也可以是不带逗号的,如
4123
479568456.56另外0,负号都是能通过的,如
0
0.00
-4567
-4,567还有就是有小数最多两位,以下都是能通过的,如
123.1
123.10
123.00
456,789.00
456,789.5
456,789.50

解决方案 »

  1.   

    Regex reg=new Regex(@"^((\d{1,3}(,\d{3})*?)|\d+)(\.\d{1,2})?$");
      

  2.   

    @"^-?((\d{1,3}(,\d{3})*?)|\d+)(\.\d{1,2})?$"
    //忘加-号了……
      

  3.   

    double d;
    Console.WriteLine(double.TryParse("479,568,456.56", 
        System.Globalization.NumberStyles.Any, null, out d).ToString());
    Console.WriteLine(double.TryParse("-479,568,456.56",
        System.Globalization.NumberStyles.Any, null, out d).ToString());
    Console.WriteLine(double.TryParse("1e-10",
        System.Globalization.NumberStyles.Any, null, out d).ToString());