在C#窗体程序中,如何判断textbox控件中输入的格式是浮点型
在C#窗体程序中,如何判断textbox控件中输入的格式是浮点型?求教,谢谢咯! --------------------编程问答-------------------- 简单点try
{
float.Parse();
}
catch
{
//不是
} --------------------编程问答-------------------- 1L方法最简单,还可以用正则判断 --------------------编程问答-------------------- Regex.IsMatch(strValue,@ "^\d+\.\d+$ ") --------------------编程问答--------------------
--------------------编程问答-------------------- using中加using System.Text.RegularExpressions;
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("不是浮点数");
}
}
}
程序中判断
Regex r = new Regex(@"^\d+\.\d+$");
if (r.IsMatch(TextBox1.Text))
{
正确
}
else
{
错误
}
补充:.NET技术 , C#