/// <summary> /// 检查颜色值是否为3/6位的合法颜色只支持#ffffff格式,rgb(0,0,0)格式不能验证通过 /// </summary> /// <param name="color">待检查的颜色</param> /// <returns></returns> public static bool IsColor(string color) { if (!IsPlumpString(color)) { return(false); } color = color.Trim(); if (color.StartsWith("#")) { return(false); } color = color.Trim('#'); if (color.Length != 3 && color.Length != 6) { return(false); } //不包含0-9 a-f以外的字符 if (!RegexHelper.IsMatch(color, "[^0-9a-f]", RegexOptions.IgnoreCase)) { return(true); } return(false); }
/// <summary> /// 是否是域名 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsDomain(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$")); }
/// <summary> /// 是否为固话号 /// </summary> public static bool IsPhone(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^(\d{3,4}-?)?\d{7,8}$")); }
/// <summary> /// 是手机号 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsMobilePhone(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$")); }
/// <summary> /// 判断是不是url /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsURL(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"[a-zA-z]+://[^s]*")); }
/// <summary> /// 判断是否是邮件地址,来自nop的方法 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsEmail(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")); }
/// <summary> /// 是否是数字 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsNumber(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^[0-9]*$")); }
/// <summary> /// 是否是时间 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsTime(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$")); }
/// <summary> /// 数字或者字母 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsNUMBER_OR_CHAR(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^[A-Za-z0-9]{4,40}$")); }
public static bool IsIPv6(string s) => IsPlumpString(s) && RegexHelper.IsMatch(s, @"/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i");
public static bool IsIPv4(string s) => IsPlumpString(s) && RegexHelper.IsMatch(s, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
/// <summary> /// 是否是IP /// </summary> public static bool IsIP(string s) => IsPlumpString(s) && RegexHelper.IsMatch(s, @"\d+\.\d+\.\d+\.\d+");
/// <summary> /// 是否是身份证号 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsIDCardNo(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$")); }
/// <summary> /// 是否是中文 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool IsChinese(string s) { return(IsPlumpString(s) && RegexHelper.IsMatch(s, @"^[\u4e00-\u9fa5]{0,}$")); }