0

I am making a website in which I need to get date from user but it should be today's date or upcoming date not previous date. Please help me to make date validation.

<input type="date" name="doj" required>

what to add in this code so that a user a can only select current date or upcoming date not previous date.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • You can just use the min attribute: http://stackoverflow.com/questions/23671407/restrict-future-dates-in-html-5-data-input – lipp Apr 24 '16 at 10:09

1 Answers1

0

You can implement using datepicker

   <script src="//code.jquery.com/jquery-1.10.2.js"></script>
   <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
   <link rel="stylesheet" ref="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all">

   <input type="text" id="strDate" name="doj" required />


    <script type="text/javascript">
    var dateToday = new Date();
        var dates = $("#strDate").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            minDate: dateToday,
            onSelect: function(selectedDate) {
                var option = this.id == "from" ? "minDate" : "maxDate",
                    instance = $(this).data("datepicker"),
                    date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                dates.not(this).datepicker("option", option, date);
            }
        });
    </script>
Samyukta R.
  • 154
  • 1
  • 1
  • 15