Winform日期格式验证(xxxx-xx-xx)

/// <summary>
        /// 日期格式判断
        /// </summary>
        /// <param name="InputStr"></param>
        /// <returns></returns>
        public static bool ValidateDataTime(string InputStr)
        {
            if (InputStr != "")
            {
                if (Regex.IsMatch(InputStr.Trim(), @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$ "))
                    return true;
                else
                    return false;
            }
            else
            {
                return false;
            }
        }

posted on 2012-06-13 11:34  ~~小麦  阅读(338)  评论(1编辑  收藏  举报

导航