正则表达式
判断字符串是只是数字我们可以这样写:
return new System.Text.RegularExpressions.Regex(@"^([0-9])[0-9]*(\.\w*)?$").IsMatch(strNumber);
或者
return System.Text.RegularExpressions.Regex.IsMatch(strNumber, @"^([0-9])[0-9]*(\.\w*)?$");
如果要判断是否全部为数字,可以用正则表达式,也可以自己判断
string str="12344";
bool IsNum(string str)
{
foreach(char ch in str)
{
if(ch<'0' || ch>'9')
return false;
}
return true;
}