首先导入命名空间:
using System.Text.RegularExpressions;
因为要用到正则表达式
private void button1_Click(object sender, EventArgs e)
{
if (IsFloat(textBox1.Text.ToString()))
{
MessageBox.Show("对,输入的全是数字", "!!!");
}
else
{
MessageBox.Show("错,不是全为数字", "!!!");
}
}
public static bool IsFloat(string inString)
{
Regex regex = new Regex(@"^\d*\.?\d*$");
return regex.IsMatch(inString.Trim());
}
using System.Text.RegularExpressions;
因为要用到正则表达式
private void button1_Click(object sender, EventArgs e)
{
if (IsFloat(textBox1.Text.ToString()))
{
MessageBox.Show("对,输入的全是数字", "!!!");
}
else
{
MessageBox.Show("错,不是全为数字", "!!!");
}
}
public static bool IsFloat(string inString)
{
Regex regex = new Regex(@"^\d*\.?\d*$");
return regex.IsMatch(inString.Trim());
}