JSFiddle - React, Tailwind, and code Playground

by Leonardo Trimarchi

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>


            <input type="text" class="date-picker form-control" placeholder="Select your age" id="age">

JavaScript

$(document).ready(function () {
        $("#age").datepicker({
            onSelect: function(value, ui) {
                var current = new Date().getTime(), 
                    dateSelect = new Date(value).getTime();
                    age = current - dateSelect;
                    ageGet = Math.floor(age / 1000 / 60 / 60 / 24 / 365.25); // age / ms / sec / min / hour / days in a year
                if(ageGet < 18){
                    less_than_18(ageGet);
                }
            },
            yearRange: '1900:+0d',//base year:current year
            changeMonth: true,
            changeYear: true,
            defaultDate: '-18yr',
        }).attr("readonly", "readonly"); //prevent manual changes


        function less_than_18(theAge){
          $( function() {
            $('<div></div>').dialog({
              modal: true,
              title: "Age Check?",
              open: function () {
                var markup = 'Applicant is not 18 years old. Do you wish to continue?';
                $(this).html(markup);
              },
              buttons: {
                'Confirm': function() {
                   $(this).dialog('close');
                },
                'Change': function() {
                   $('#age').val('');
                   $(this).dialog('close');
                }
              }
            });
          } );  
        }

    });
    
     $(".date-picker").datepicker();
     $(".date-picker").on("change", function () {
    var id = $(this).attr("id");
    var val = $("label[for='" + id + "']").text();
    $("#msg").text(val + " changed");
});