出生日期的 DatePicker 验证

DatePicker validation for Date of Birth

我希望用户能够 select 从现在起至多 18 年后的日期(即用户必须年满 18 岁才能申请)。这是我迄今为止尝试过的方法。

HTML

<!-- Date input --->
        <div class="form-group">
            <label class="col-md-4 control-label" for="date">DOB</label>
            <div class="col-md-4">
                <input class="form-control" id="date" name="date" placeholder="MM/DD/YYYY" type="text" required="">
            </div>
        </div>

JS

<script>
    $(document).ready(function(){
        var date_input=$('input[name="date"]'); //our date input has the name "date"
        var container=$('.form-horizontal').length>0 ? $('.form-horizontal').parent() : "body";
        date_input.datepicker({
            format: 'mm/dd/yyyy',
            endDate: '-18y',
            container: container,
            todayHighlight: true,
            autoclose: true,
            orientation: "top",
        })
    })
</script>

我和我的追随者一起测试了 endDate 但 none 似乎有效

-18y

-18yyyy

18years

它对我来说工作正常,请检查,可能有一些其他的变化影响了。 https://jsfiddle.net/ouy7Ldfw/

date_input.datepicker({
        format: 'mm/dd/yyyy',
        endDate: '-18y',
        container: container,
        todayHighlight: true,
        autoclose: true,
        orientation: "top",
    })