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;  
      }
  • 相关阅读:
    服务级后门自己做——创建服务
    使用Win32创建串口通讯程序
    LoadImage with resource 出现未定义
    direct path write等待事件
    enq: TX row lock/index contention、allocate ITL等待事件
    enq: TT contention等待事件
    enq: TM contention等待事件
    enq: RO fast object reuse等待事件
    direct path write temp等待事件
    enq: US contention等待事件
  • 原文地址:https://www.cnblogs.com/sontin/p/1929811.html
Copyright © 2011-2022 走看看