方法一(字符串处理):
public static bool IsNum(string str)
{
bool blResult = true;//默认状态下是数字
if(str == "")
blResult = false;
else
{
foreach(char Char in str)
{
if(!char.IsNumber(Char))
{
blResult = false;
break;
}
}
if(blResult)
{
if(int.Parse(str) == 0)
blResult = false;
}
}
return blResult;
}
方法二(正则表达式):
static bool IsNumeric(string str)
{
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$");
return reg1.IsMatch(str);
}