您的位置:首页 > 编程语言 > C#

在C#.net中使用正则表达式检验输入是否为数字

2009-01-07 15:13 555 查看
在C#.net中使用正则表达式检验输入是否为数字

using System.Text.RegularExpressions;

private static bool IsNumeric(string itemValue)
{
return (IsRegEx("^(-?[0-9]*[.]*[0-9]{0,3})$", itemValue));
}

private static bool IsRegEx(string regExValue, string itemValue)
{

try
{
Regex regex = new System.Text.RegularExpressions.Regex(regExValue);
if (regex.IsMatch(itemValue)) return true;
else return false;
}
catch (Exception )
{
return false;
}
finally
{
}
}

上面这个其实不对

if (!System.Text.RegularExpressions.Regex.IsMatch(temp, @"^[-]?/d+[.]?/d*$"))

这个也许差不多

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐