twitter-bootstrap Bootstrap 日期时间选择器中的出生日期验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23080556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:30:31  来源:igfitidea点击:

Date of birth validation in Bootstrap datetime picker

javascriptjquerytwitter-bootstrapdatedatetime

提问by Raghavendra

I am using Bootstrap datetime picker to select date for date of birth. Now I want to validate it as it has to show the dates from 1985 to 1995 so here is my fiddle: http://jsfiddle.net/raghavendram040/4wwJy/

我正在使用 Bootstrap 日期时间选择器来选择出生日期。现在我想验证它,因为它必须显示从 1985 年到 1995 年的日期,所以这是我的小提琴:http: //jsfiddle.net/raghavendram040/4wwJy/

Here is my JS for datetime picker:

这是我用于日期时间选择器的 JS:

$('.form_date1').datetimepicker({
    // language: 'fr',    
    weekStart: 1,
    todayBtn:  1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 4,
    keyboardNavigation:1,
    minView: 2,
    forceParse: 0
});

So how can I validate it for date of birth with above requirement?

那么如何根据上述要求验证出生日期呢?

回答by Tushar Gupta - curioustushar

Restrict use to select date between the date range of year 1985to 1995

限制用于在年份1985到的日期范围之间选择日期1995

Fiddle Demo

Fiddle Demo

$(function () {
    var startDate = new Date('1985-01-01'),
        endDate = new Date('1995-01-01');
    $('#from-datepicker').datetimepicker({
        //other option
        startDate: startDate, //set start date
        endDate: endDate //set end date
    });
});



HTMLHTML

<div id="from-datepicker" class="input-append date">
    <input data-format="dd/MM/yyyy" type="text" value="01/01/1985"></input><span class="add-on" />
</div>