标签:bool xxx string pos style 一个 param return ext
/// <summary> /// 是否手机号 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool isPhone(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[1]+[3,5,8]+\d{9}"); } /// <summary> /// 是否为xxxx-xx-xx的时间格式 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool isDateTime(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"\d{4}-(1[0-2]|[0]?\d)-(3[01]|[0-2]?\d)"); } /// <summary> /// 是否为4个汉字以内(含4个)的名字 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool isName(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[\u4E00-\u9FA5]{0,4}$"); } /// <summary> /// 验证身份号证 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsIDcard(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"(^\d{18}$)|(^\d{15}$)"); } /// <summary> /// 验证是否为邮政编码 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsPostalcode(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"^\d{6}$"); } /// <summary> /// 验证是否为邮箱 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool isEmail(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"\w+([-+.‘]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); } /// <summary> /// 验证是否是纯数字和字母组合 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsNumAndWord(string str){ return System.Text.RegularExpressions.Regex.IsMatch(str, @"^(-?\d+)(\.\d+)$"); } /// <summary> /// 验证是否是纯字母 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsWord(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[a-zA-Z]+$"); } /// <summary> /// 验证六位数以上数字,符号,字母任意两种混合的密码验证策略 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool ishunhe(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[a ^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-zA-Z]|[0-9]){6,}$"); } /// <summary> /// 判断是否为双精度 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool isDouble(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[-\+]?\d+(\.\d+)$"); }
所有的正则都是在网上找的,这里做了一个总结,有所错误请指正。
标签:bool xxx string pos style 一个 param return ext
原文地址:https://www.cnblogs.com/widows/p/9117858.html