下面是偶曾经用到的,只能按照0.0的格式输入数字
private void textBox9_TextChanged(object sender, EventArgs e)
{
int k = 0;
for (int i = 0; i < textBox9.Text.Length; i++)
{
if (textBox9.Text[i] == '.')
{
k += 1;
}
if (((textBox9.Text[i] < '0' || textBox9.Text[i] > '9') && textBox9.Text[i] != '.') || k > 1)
{
MessageBox.Show("请输入数字,请按照'0.0'的格式输入");
textBox9.Text = "";
}
if (i == 0) //第一个输入不能为'.'
{
if (textBox9.Text.Trim() != "")
{
if (textBox9.Text[0] == '.')
{
MessageBox.Show("输入非法字符,请按照'0.0'的格式输入");
textBox9.Text = "";
}
}
}
}
}