Ejemplo n.º 1
0
        /// <summary>
        /// 验证输入字符串是否为日期
        /// </summary>
        /// <param name="inputStr">输入的字符串</param>
        /// <param name="Delimiter">分隔符</param>
        /// <returns>
        /// true是日期
        /// false不是日期
        /// </returns>
        public static bool MIsDate(this string inputStr, string Delimiter = "-/.")
        {
            bool resM = false;

            if (inputStr.MVerifyRegex(RegexData.REG_Date(Delimiter), true))
            {
                char[]   Delimiters = Delimiter.ToCharArray();
                string[] dateStr    = new string[3];
                for (int i = 0; i < Delimiters.Length; i++)
                {
                    dateStr = inputStr.Split(Delimiters[i]);
                    if (dateStr.Length == 3)
                    {
                        int Month = int.Parse(dateStr[1]);
                        if (Month == 2)
                        {
                            int Year = int.Parse(dateStr[0]);
                            int day  = int.Parse(dateStr[2]);
                            if (Year % 4 == 0)
                            {
                                resM = true;
                            }
                            else
                            {
                                if (day <= 28)
                                {
                                    resM = true;
                                }
                            }
                        }
                        else
                        {
                            resM = true;
                        }
                        break;
                    }
                }
            }
            return(resM);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取输入字符串中所有的日期
 /// </summary>
 /// <param name="inputStr">输入的字符串</param>
 /// <param name="Delimiter">分隔符</param>
 /// <returns>
 /// 字符串中所有的日期
 /// </returns>
 public static MatchCollection MGetDateInStr(this string inputStr, string Delimiter = "-/.")
 {
     return(inputStr.MGetVerifyRegex(RegexData.REG_Date(Delimiter), false));
 }