吴旭晓个人博客 繁体中文 简体中文

首页| 日志 |JAVA |ASP |PHP |Android |IOS |ASP.NET |JavaScript |DIV+CSS |SEO |taobaoke |饼哥语录
繁体中文 简体中文

.Net中判断日期时间输入是否合法(使用正则表达式)

.Net中判断日期时间输入是否合法(使用正则表达式)  

^((((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-))$


public static bool validateDatetime(string strValue)
{
   string strReg = @"([1-2][0-9][0-9][0-9])-(0*[1-9]|1[0-2])-(0*[1-9]|[12][0-9]|3[01])\ (0*[0-9]|1[0-9]|2[0-3]):(0*[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])";  
   if (strValue == "")
   {
    return false;
   }
   else
   {
    Regex re = new Regex(strReg);
    MatchCollection  mc = re.Matches(strValue);
    if (mc.Count == 1)
     foreach(Match m in mc)
     {
      if (m.Value == strValue)
       return true;
     }
   }
   return false;
}


这个太xxxxxxxxx了

 程序代码
public   bool   IsDate(string   str)  
  {  
            bool   Result=true;  
            try  
              {  
                    System.Convert.ToDateTime(str);  
              }  
              catch  
              {  
                        Result=false;  
                }  
      return   Result;  
  }

作者:吴旭晓 | 来源:个人博客 | 点击量:2730 | 发布时间:2013-08-22
最新留言 | 返回上一页 | 返回首页

相关文章:

版权所有:吴旭晓个人博客 Copyright © 2013-2023 个人博客