您的位置:首页 > 其它

用正则表达式来判断是否有需要的字符串

2016-03-16 13:57 357 查看
/// <summary>
/// 判断文本框中输入是否为【数字】
/// </summary>
/// <param name="itemValue"></param>
/// <returns></returns>
private static bool IsNumeric(string itemValue)
{
return (IsRegEx("^(-?[0-9]*[.]*[0-9]{0,3})$", itemValue));
}
/// <summary>
/// 判断文本框中输入是否为【数字,字母】
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsNatural_Number(string str)
{
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z0-9]+$");
return reg1.IsMatch(str);
}
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: