How to validate a date that can't be greater than current date?

Check date not be greater than current date.

Get the jQuery code below to check a date that can't be greater than current date:

 

$('.ty-dob input').change(function(){
                
    dob          = $(this).val();
    
    var current_date = new Date();

    var arrDate = dob.split("/");

    var dob = new Date(arrDate[2], arrDate[1]-1, arrDate[0]);
    
    /*console.log(arrDate);
    console.log(arrDate[2]+', '+arrDate[1]+','+ arrDate[0]);
    console.log(dob);
    console.log(current_date);*/
    if(dob > current_date)
    {
        alert("Date can not be greater than current date.");
        $(this).val('');
        return false;
    }
});

 

Here ".ty-dob input" is the date field to accept a date from datepicker.  If dob is greater than current date, it makes the field empty prompting an alert message to choose another date.