js常用的几个验证

时间:2025-03-12 13:37:25
 /// <summary>
///1. 使用正则表达式验证 参数 是否 为数值
/// </summary>
/// <param name="trNumber"></param>
/// <returns></returns>
public static bool IsNum(string trNumber)
{
Regex Re = new Regex(@"^\d+$");
return Re.IsMatch(trNumber);
}
}
 /// <summary>
///2. 使用正则表达式验证 参数 是否为 6-12个整数或字母,或下滑线
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsHeFa(string str)
{
Regex reg = new Regex(@"^w{6,12}$");
return reg.IsMatch(str);
}