C#验证输入的是否数字的方法
日期:2007年9月9日 作者: 查看:[大字体 中字体 小字体]-
其实用正则表达式也可以
static bool IsNumeric(string str)
{
if (str==null str.Length==0)
return false;
foreach(char c in str)
{
if (!Char.IsNumber(c))
{
return false;
}
}
return true;
}正则表达的写法是:
static bool IsNumeric(string str)
{
System.Text.RegularEXPressions.Regex reg1
= new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
return reg1.IsMatch(str);
}
(出处:网侠)
下一篇:连接字符串集合
