我使用的是twitter bootstrap中的日期选择器,我想添加一些验证,如果您的日期低于18岁,您的注册将不会被认为是已注册的,我该如何去做?这里是我的出生日期的示例html代码:日期选择器验证18岁
<label>Date of Birth*</label>
<input type="date" name="birth_date" tabindex="7" style="height: 30px;" required>
我使用的是twitter bootstrap中的日期选择器,我想添加一些验证,如果您的日期低于18岁,您的注册将不会被认为是已注册的,我该如何去做?这里是我的出生日期的示例html代码:日期选择器验证18岁
<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';
}
}
设置基于今天的日期的'min'属性 - 18年(HTML5)。但是,无论如何,你必须在服务器端和/或js上检查它。 – Cheery 2014-10-28 17:50:25
最好的方法是进行JavaScript限制用户体验和PHP的安全限制。 – gr3g 2014-10-28 17:51:08
对不起,但我不知道如何在JavaScript中做到这一点,我只是一个初学者在开发..所以对不起,有人会告诉我如何做到这一点? – user3819129 2014-10-28 17:53:23