Disable future dates in date picker

Using the below code we can disable the future dates in the date picker.


<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

 <script>
             $(document).ready(function () {
                var currentDate = new Date();
                $('.disableFuturedate').datepicker({
                format: 'dd/mm/yyyy',
                autoclose:true,
                endDate: "currentDate",
                maxDate: currentDate
                }).on('changeDate', function (ev) {
                   $(this).datepicker('hide');
                });
                $('.disableFuturedate').keyup(function () {
                   if (this.value.match(/[^0-9]/g)) {
                      this.value = this.value.replace(/[^0-9^-]/g, '');
                   }
                });
             });
          </script>

Leave a comment

Your email address will not be published. Required fields are marked *