user2650277
user2650277

Reputation: 6739

DatePicker validation for Date of Birth

I want the user to be able to select a date that is at most 18 years from now(i.e users must be 18+ to apply).Here is what i tried thus far.

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>

I tested with my following for endDate but none seems to work

-18y

-18yyyy

18years

Upvotes: 0

Views: 886

Answers (1)

Siddaram H
Siddaram H

Reputation: 1176

It is working fine for me, please check, there might be some other changes that have affected. https://jsfiddle.net/ouy7Ldfw/

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

Upvotes: 1

Related Questions