JavaScript出生日期验证

JavaScript出生日期验证,javascript,validation,date,date-of-birth,Javascript,Validation,Date,Date Of Birth,它正在工作。非常感谢! 编辑我正在使用Dreamweaver和HTML,我想我在帖子上错选了C 我正在尝试添加一个验证,如果D.O.B超过18岁,则在尝试提交时会输出一个错误。我无法让它与其他验证一起工作 <form action="http://posttestserver.com/post.php" method="post"> <!--action="contact.php" name="form1" id="form1"> --> <!-- sta

它正在工作。非常感谢! 编辑我正在使用Dreamweaver和HTML,我想我在帖子上错选了C

我正在尝试添加一个验证,如果D.O.B超过18岁,则在尝试提交时会输出一个错误。我无法让它与其他验证一起工作

<form action="http://posttestserver.com/post.php" method="post">
<!--action="contact.php" name="form1" id="form1">
 -->
 <!-- stackoverflow.com, w3schools.com-->
First Name <input type="text" name="firstName" value="First Name" required/>
<br>
Last Name <input type="text" name="lastName" value="Last Name" required/>
<br>
Date of Birth <input type="date" name="dob" required/>
<br>
Address <input type="text" name="address" required/>
<br>
Mobile Number <input type="number" name="mobile" required/>
<br>
  Email Address  <input name="email" type="email" value="@." required id="email"/>
  <br>
   Re-enter Email Address <input name="emailConfirm" type="email" id="confemail" value="@." onblur="confirmEmail()"/>
   <br>
<input type="submit" name="submit" value="Submit Data"/>
<br>
</form>

您给出的代码可能还有其他问题,但我注意到的第一个问题是函数
AgeValidation
没有使用它的参数
ageOfCustomer
,而是使用未定义的
saildates
变量。

看看这个。决定年龄的函数如下

function get_age(born, now) {
      var birthday = new Date(now.getFullYear(), born.getMonth(), born.getDate());
      if (now >= birthday) 
        return now.getFullYear() - born.getFullYear();
      else
        return now.getFullYear() - born.getFullYear() - 1;
    }

1.您没有在任何地方调用
AgeValidation()。2.您正在传入
ageOfCustomer
,但试图使用名为
saildate
的未定义变量。3.假设有一个值,它使用“/”(Chrome提供了一个日期选择器,该值的格式为“YYYY-MM-DD”)。非常感谢,它看起来是正确的。我试着在代码中实现它,但它似乎没有在HTML中检测到它。使用Dremweaver CS5.1和HTML5。
function get_age(born, now) {
      var birthday = new Date(now.getFullYear(), born.getMonth(), born.getDate());
      if (now >= birthday) 
        return now.getFullYear() - born.getFullYear();
      else
        return now.getFullYear() - born.getFullYear() - 1;
    }