Exemplo n.º 1
0
        /// <summary> 是否是路径 </summary>
        public static bool IsPath(this IGroupMatchString path)
        {
            string pattern = @"^[a-zA-Z]:(((\\(?! )[^/:*?<>\""|\\]+)+\\?)|(\\)?)\s*$";
            Regex  regex   = new Regex(pattern);

            return(regex.IsMatch(path.Value));
        }
Exemplo n.º 2
0
        ///  <summary> 判断输入的字符串是否是合法的IPV6 地址 </summary>
        public static bool IsIPV6(this IGroupMatchString input)
        {
            string pattern = "";
            string temp    = input.Value;

            string[] strs = temp.Split(':');
            if (strs.Length > 8)
            {
                return(false);
            }
            int count = GetStringCount(input.Value, "::");

            if (count > 1)
            {
                return(false);
            }
            else if (count == 0)
            {
                pattern = @"^([\da-f]{1,4}:){7}[\da-f]{1,4}$";
                return(IsMatch(pattern, input.Value));
            }
            else
            {
                pattern = @"^([\da-f]{1,4}:){0,5}::([\da-f]{1,4}:){0,5}[\da-f]{1,4}$";
                return(IsMatch(pattern, input.Value));
            }
        }
Exemplo n.º 3
0
 /// <summary> 是否是GUID </summary>
 public static bool IsGUID(this IGroupMatchString expression)
 {
     if (expression != null)
     {
         Regex guidRegEx = new Regex(@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
         return(guidRegEx.IsMatch(expression.Value));
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 是否是日期的字符串
        /// </summary>
        /// <param name="path">只对这些格式进行验证("d'MMM'yyyy", "dd'MMM'yyyy")</param>
        /// <returns></returns>
        public static bool IsDate(this IGroupMatchString path)
        {
            string   path1 = path.Replace("'", "").Replace(" ", "");
            DateTime parseDate;

            string[] formats = { "dMMMyyyy", "ddMMMyyyy" };
            if (DateTime.TryParseExact(path1, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite, out parseDate))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        ///  <summary> 判断输入的字符串是否是表示一个IP地址 </summary>
        public static bool IsIPv4(this IGroupMatchString input)
        {
            string[] IPs = input.Value.Split('.');

            for (int i = 0; i < IPs.Length; i++)
            {
                if (!IsMatch(@"^\d+$", IPs[i]))
                {
                    return(false);
                }
                if (Convert.ToUInt16(IPs[i]) > 255)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 6
0
        /// <summary> 验证是否含有^%&'',;=?$"等字符:“[^%&'',;=?$x22]+” </summary>
        public static bool IsComtain(this IGroupMatchString input)
        {
            string pattern = @"[^%&'',;=?$x22]+";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 7
0
        /// <summary> 验证一年的12个月:“^(0?[1-9]|1[0-2])$”正确格式为:“01”-“09”和“1”“12” </summary>
        public static bool IsMonth(this IGroupMatchString input)
        {
            string pattern = @"^(0?[1-9]|1[0-2])$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 8
0
        ///  <summary> 判断输入的字符串是否是一个超链接 </summary>
        public static bool IsURL(this IGroupMatchString input)
        {
            string pattern = @"^[a-zA-Z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 9
0
        /// <summary> ^w+$  //匹配由数字、26个英文字母或者下划线组成的字符串 </summary>
        public static bool IsNumOrEngOrUndLine(this IGroupMatchString input)
        {
            string pattern = @"^w+$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 10
0
        /// <summary> ^[a-z]+$  //匹配由26个英文字母的小写组成的字符串 </summary>
        public static bool IsEnglishLetter(this IGroupMatchString input)
        {
            string pattern = @"^[a-z]+$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 11
0
        ///  <summary> 判断输入的字符串是否是一个合法的Email地址 </summary>
        public static bool IsEmail(this IGroupMatchString input)
        {
            string pattern = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 12
0
        /// <summary> 只能输入有两位小数的正实数:“^[0-9]+(.[0-9]{2})?$” </summary>
        public static bool IsLenthDecimal(this IGroupMatchString input)
        {
            string pattern = @"^[0-9]+(.[0-9]{2})?$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 13
0
        /// <summary> 匹配中文字符的正则表达式: [u4e00-u9fa5] </summary>
        public static bool IsChineseChar(this IGroupMatchString input)
        {
            string pattern = @"[u4e00-u9fa5]";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 14
0
        /// <summary> 只能输入m-n位的数字:“^d{m,n}$” </summary>
        public static bool IsBetweenNumber(this IGroupMatchString input, int minLen, int maxLen)
        {
            string pattern = @"^d{" + minLen + "," + maxLen + "}$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 15
0
        /// <summary> 只能输入零和非零开头的数字:“^(0|[1-9][0-9]*)$” </summary>
        public static bool IsStartWithZoreNum(this IGroupMatchString input)
        {
            string pattern = @"^(0|[1-9][0-9]*)$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 16
0
        /// <summary> 只能输入至少n位数字:“^d{n,}$” </summary>
        public static bool IsLeastLenNum(this IGroupMatchString input, int minLenth)
        {
            string pattern = @"^d{" + minLenth + ",}$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 17
0
        /// <summary> 只能输入n位的数字:“^d{n}$”  </summary>
        public static bool IsLenghNumber(this IGroupMatchString input, int length)
        {
            string pattern = @"^d{" + length + "}$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 18
0
        /// <summary> 只能输入数字:“^[0-9]*$” </summary>
        public static bool IsNumberOnly(this IGroupMatchString input)
        {
            string pattern = @"^[0-9]*$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 19
0
 ///  <summary> 判断输入的字符串字包含英文字母 </summary>
 public static bool IsEnglisCh(this IGroupMatchString input)
 {
     return(IsMatch(@"^[A-Za-z]+$", input.Value));
 }
Exemplo n.º 20
0
        /// <summary> 只能输入有1-3位小数的正实数:“^[0-9]+(.[0-9]{1,3})?$” </summary>
        public static bool IsURealNum(this IGroupMatchString input)
        {
            string pattern = @"^[0-9]+(.[0-9]{1,3})?$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 21
0
        /// <summary> 验证一个月的31天:“^((0?[1-9])|((1|2)[0-9])|30|31)$” 正确格式为:“01”“09”和“1”“31” </summary>
        public static bool IsDay(this IGroupMatchString input)
        {
            string pattern = @"^((0?[1-9])|((1|2)[0-9])|30|31)$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 22
0
 ///  <summary> 匹配正整数 </summary>
 public static bool IsUint(this IGroupMatchString input)
 {
     return(IsMatch(@"^[0-9]*[1-9][0-9]*$", input.Value));
 }
Exemplo n.º 23
0
        /// <summary> ^[A-Za-z0-9]+$  //匹配由数字和26个英文字母组成的字符串  </summary>
        public static bool IsNumOrEnglish(this IGroupMatchString input)
        {
            string pattern = @"^[A-Za-z0-9]+$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 24
0
        /// <summary> ^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$  //匹配非正浮点数(负浮点数 + 0) 评注:处理大量数据时有用,具体应用时注意修正 </summary>
        public static bool IsNotUFloat(this IGroupMatchString input)
        {
            string pattern = @"^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 25
0
        /// <summary> ^[A-Za-z]  //匹配由26个英文字母开始的字符串 </summary>
        public static bool IsStartEnglish(this IGroupMatchString input)
        {
            string pattern = @"^[a-zA-Z]";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 26
0
        /// <summary> 只能输入长度为3的字符:“^.{3}$” </summary>
        public static bool IsLenghChar(this IGroupMatchString input)
        {
            string pattern = @"^.{3}$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 27
0
 ///  <summary> 判断输入的字符串是否只包含数字和英文字母 </summary>
 public static bool IsNumAndEnCh(this IGroupMatchString input)
 {
     return(IsMatch(@"^[A-Za-z0-9]+$", input.Value));
 }
Exemplo n.º 28
0
        /// <summary> 验证用户密码:“^[a-zA-Z]w{5,17}$”正确格式为:以字母开头,长度在6-18之间,只能包含字符、数字和下划线 </summary>
        public static bool IsUserPassWord(this IGroupMatchString input)
        {
            string pattern = @"^[a-zA-Z]w{5,17}$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 29
0
        /// <summary> 只能输入非零的负整数:“^-[1-9][0-9]*$” </summary>
        public static bool IsMIntExceptZore(this IGroupMatchString input)
        {
            string pattern = @"^-[1-9][0-9]*$";

            return(IsMatch(pattern, input.Value));
        }
Exemplo n.º 30
0
 ///  <summary> 匹配非负整数 </summary>
 public static bool IsNotNagtive(this IGroupMatchString input)
 {
     return(IsMatch(@"^\d+$", input.Value));
 }