Ramil Signh Ramil Signh - 6 months ago 15
Javascript Question

How to determine if the user is 18 years old and up using jquery?

I want to determine if the user is 18 years old and up using jquery.
Can anyone give me a sample code. I am using datepicker.

Thanks in advance!

Answer

Try this:

Jquery:

        $('#datepicker').datepicker({
            onSelect: function(value, ui) {
                var today = new Date(), 
                    age = today.getFullYear() - ui.selectedYear;
                if(age >= 18)
                    $('#age').text("User is 18 years old");
                else
                    $('#age').text("User is 18 not years old");
            },
            maxDate: '+0d',
            changeMonth: true,
            changeYear: true,
            yearRange: '-110:-30'

        });

Html:

<input type="text" id="datepicker" />
<div id="age" />
Comments