当前位置:编程学习 > JSP >>

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

答案:直接调用以下函数进行检验,返回值为true表示输入是数字,反之不是。
itemValue为输入的值。

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
{
}
}


上一个:Eclipse + Lomboz + Tomcat JSP 开发配置
下一个:在JSP中访问数据库大全

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,