需要验证出生日期用户应年满 18 岁

Need to validate Date of birth user should be 18 years and more

我正在使用 bootstrap-datepicker.js 从日历中获取出生日期,我需要禁用过去的日期,它应该在日历中 18 年后启用。请帮我解决这个问题。

这正在使用 moment.js

moment("1999-03-22").isBefore(moment().subtract(18, "years"))

如果第一个括号中的日期基于当前日期至少是 18 年前,则 return 为真。

可以尝试使用最大日期属性集对其进行初始化

$("#datePickerId").datepicker({
    maxDate: "-18Y"
});

jQuery datepicker mindate, maxdate