zoukankan      html  css  js  c++  java
  • 验证日期的Javascript

    验证输入的日期是否是dd/MM/yyyy格式,并且最后判断是否大于等于当前日期。
    function ValidateDate(strValue)
            
    {
                
    var objRegExp = /^(\d{2})\/(\d{2})\/(\d{4})$/;
                
    if(!objRegExp.test(strValue)) 
                    
    return false;  
                
    else
                

                    
    var arrayDate = strValue.split('/');  
                    
    var intDay = parseInt(arrayDate[0],10); 
                    
    var intYear = parseInt(arrayDate[2],10); 
                    
    var intMonth = parseInt(arrayDate[1],10); 
                    
    if(intMonth > 12 || intMonth < 1return false
                    
    var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,  '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31};
                    
    if(arrayLookup[intMonth] != null
                    

                        
    if(intDay > arrayLookup[intMonth] || intDay == 0
                        
    return false;
                    }
     
                    
    if (intMonth==2
                    

                        
    var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0)); 
                        
    if( ((booLeapYear && intDay > 29|| (!booLeapYear && intDay >28)) || intDay ==0
                            
    return false
                    }
     
                    
    var currentDate = new Date();
                    
    var cYear = currentDate.getFullYear();
                    
    var cMonth = currentDate.getMonth()+1;
                    
    var cDay = currentDate.getDate();
                    
    if(cYear*10000+cMonth*100+cDay > intYear*10000+intMonth*100+intDay)
                        
    return false
                }

                
    return true;
            }
  • 相关阅读:
    python学习笔记(excel中处理日期格式)
    python学习笔记(生成xml)
    python学习笔记(接口自动化框架 V1.0)
    python学习笔记(excel+unittest)
    刷题[RoarCTF 2019]Easy Java
    刷题[GKCTF2020]
    php bypass disable function
    刷题[MRCTF2020]Ezpop
    刷题[安恒DASCTF2020四月春季赛]Ez unserialize
    刷题[HFCTF2020]EasyLogin
  • 原文地址:https://www.cnblogs.com/Don/p/982220.html
Copyright © 2011-2022 走看看