Example #1
0
 public static RegexUtil GetInstance()
 {
     if (RegexUtil.instance == null)
     {
         RegexUtil.instance = new RegexUtil();
     }
     return(RegexUtil.instance);
 }
Example #2
0
        /// <summary>
        /// 判断输入的字符串是否是合法的IPV6 地址
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsIPV6(string input)
        {
            /* *******************************************************************
             * 1、通过“:”来分割字符串看得到的字符串数组长度是否小于等于8
             * 2、判断输入的IPV6字符串中是否有“::”。
             * 3、如果没有“::”采用 ^([\da-f]{1,4}:){7}[\da-f]{1,4}$ 来判断
             * 4、如果有“::” ,判断"::"是否止出现一次
             * 5、如果出现一次以上 返回false
             * 6、^([\da-f]{1,4}:){0,5}::([\da-f]{1,4}:){0,5}[\da-f]{1,4}$
             * ******************************************************************/

            string pattern = "";
            string temp    = input;

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

            if (count > 1)
            {
                return(false);
            }
            else if (count == 0)
            {
                pattern = @"^([\da-f]{1,4}:){7}[\da-f]{1,4}$";

                Regex regex = new Regex(pattern);
                return(regex.IsMatch(input));
            }
            else
            {
                pattern = @"^([\da-f]{1,4}:){0,5}::([\da-f]{1,4}:){0,5}[\da-f]{1,4}$";
                Regex regex1 = new Regex(pattern);
                return(regex1.IsMatch(input));
            }
        }
Example #3
0
 /// <summary>
 /// 判断是否为合法日期,必须大于1800年1月1日
 /// </summary>
 /// <param name="strDate">输入日期字符串</param>
 /// <returns>True/False</returns>
 public static bool IsDateTime(string strDate)
 {
     return(RegexUtil.IsDateTime(strDate));
 }