/// <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;
}
}
用正则表达式来判断是否有需要的字符串
最新推荐文章于 2022-04-16 11:07:56 发布