zoukankan      html  css  js  c++  java
  • .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;  
      }
  • 相关阅读:
    Servlet核心技术(上)
    Bootstrap详解
    ECMAScript6详解
    JQuery详解
    CSS详解
    HTML
    网站加载页面(HTML+CSS+JS,简易版)
    java中sort()方法的用法
    Maven常见jar包依赖
    解决idea的项目启动报404的问题
  • 原文地址:https://www.cnblogs.com/sontin/p/1929811.html
Copyright © 2011-2022 走看看