yyyymmdd时间格式的校验

<html>
 <head>
  <script type="text/javascript">
   function validate_birthday(){
    var birthday = myform.birthday.value.replace(/(\s*$)/g, "");
    myform.birthday.value = myform.birthday.value.replace(/(\s*$)/g, "");
    var date_reg = /^[12]\d{3}(1[12]|0[1-9])(0[1-9]|1\d|2\d|3[01])$/;
    if(birthday==""){
      alert("生日不能为空!");
      myform.birthday.focus();
      return false;
    }
    if(!date_reg.test(birthday)){
      alert("生日格式不正确!");
      myform.birthday.focus();
      return false;
    }else{
      
    }
   }
  </script>
 </head>
 <body>
  <form name="myform">
   生日:<input type="text" name="birthday">(格式:20090112)
   <input type="button" value="验证" onclick="validate_birthday();">
  </form>
 </body>
</html>
posted @ 2009-02-20 11:26  枣阳人在深圳  阅读(403)  评论(0)    收藏  举报