private bool IsNum(string str)
{
try
{
foreach (char c in str)
{
if (char.IsDigit(c))
return true;
return false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
正则表达式:
Regex r=new Regex(@^\d+(\.)?\d*$);
if(r.IsMatch(this.TextBox1.Text))
{
this.Response.Write(是数字);
}
else
{
this.Response.Write(不是数字);
}
输入的是不是字母:
foreach (char c in str)
{
if (char.IsLetter(c))
return true; return false;
}