在C#窗体程序中,如何判断textbox控件中输入的格式是浮点型?求教,谢谢咯!

解决方案 »

  1.   

    简单点
    try
    {
    float.Parse();
    }
    catch
    {
    //不是
    }
      

  2.   

    Regex.IsMatch(strValue,@ "^\d+\.\d+$ ") 
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication9
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = "123.123";
                if (Regex.IsMatch(s, @"^\d+\.\d+$"))
                {
                    Console.WriteLine("浮点数");
                }
                else
                    Console.WriteLine("不是浮点数");
            }
        }
    }
      

  4.   

    using中加using System.Text.RegularExpressions;程序中判断
    Regex r = new Regex(@"^\d+\.\d+$");
    if (r.IsMatch(TextBox1.Text))
    {
         正确
    }
    else
    {
        错误
    }