日期选择器验证18岁


Datepicker validation 18 years of age

我使用的是twitter引导程序中的日期选择器,我想添加一些验证,即一旦你的约会对象低于18岁,你的注册就不会被注册,我该怎么做?这是我的出生日期示例html代码:

<label>Date of Birth*</label>
<input type="date" name="birth_date" tabindex="7" style="height: 30px;" required>

如果向下看演示页面,您会看到"限制日期选择器"部分。使用下拉列表指定"年份下拉列表显示最近20年"演示,然后点击视图来源:

$("#restricting").datepicker({ 
    yearRange: "-20:+0", // this is the option you're looking for
    showOn: "both", 
    buttonImage: "templates/images/calendar.gif", 
    buttonImageOnly: true 
});

你也会想做同样的事情(显然是将-20改为-100或其他什么)。

或者你可以使用

$('#dp1').datepicker({
    format: 'mm-dd-yyyy',
    startDate: '-15d',
    endDate: '+0d' // there's no convenient "right now" notation yet
});

您需要使用javascript或将要使用的脚本语言来验证用户输入。

PHP中的一个例子是:

<?php
if(isset($_POST['birth_date']))
{
   if($_POST['birth_date'] < 1996)
   {
      echo 'You can not register';
   }
}