使用jquery进行日期validation,防止进入昨天的日期。

我正在尝试validation日期输入字段。 我可以阻止jquery datepicker阻止输入旧日期,

$('#delivery_date').datePicker({ minDate: 0 }); 

但是用户仍然可以手动输入日期。 如何预防或validation这一点?

 // when the field changes value $('#delivery_date').on('change',function(){ var today = new Date(); today = new Date(today.getYear(), today.getMonth(), today.getDate()); // compare the value of the field with whatever you want to test against if($(this).val() > today){ // if the test fails, change the value to default $(this).datepicker('setDate', new Date()); } }) 
 $('#delivery_date').on('change', function(){ var today = new Date(); if(new Date($(this).val()) < new Date(today.getYear(), today.getMonth() - 1, today.getDate()) $(this).datepicker('setDate', new Date()); });