Home > Web Front-end > JS Tutorial > body text

JS verification date format YYYY-mm-dd specific implementation_javascript skills

WBOY
Release: 2016-05-16 17:30:47
Original
1347 people have browsed it
复制代码 代码如下:

function checkInputDate(obj){
   var   strDate=obj.value;
   var  re =/^(d{4})-(d{2})-(d{2})$/;
   if(re.test(strDate))//判断日期格式符合YYYY-MM-DD标准
   {
    var   dateElement=new   Date(RegExp.$1,parseInt(RegExp.$2,10)-1,RegExp.$3);
     if(!((dateElement.getFullYear()==parseInt(RegExp.$1))&&((dateElement.getMonth() 1)==parseInt(RegExp.$2,10))&&(dateElement.getDate()==parseInt(RegExp.$3))))//判断日期逻辑
     {
       document.getElementById("errorMessage").innerText = "You can only input Date.(YYYY-MM-DD) !";
       document.getElementById("error").style.display = "";
       obj.value= ' ';
      }
   }else{
    document.getElementById("errorMessage").innerText = "You can only input Date.(YYYY-MM-DD)!";
       document.getElementById("error").style.display = "";
       obj.value= '';
   }
 }
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template