使用jquery进行日期验证,防止输入yeterdays日期。

使用jquery进行日期验证,防止输入yeterdays日期。,jquery,validation,date,Jquery,Validation,Date,我正在尝试验证日期输入字段。 我可以防止jquery datepicker使用 $('#delivery_date').datePicker({ minDate: 0 }); 但用户仍然可以手动输入日期。如何防止或验证这一点 $('#交货日期')。在('change',function(){ $('#delivery_date').on('change', function(){ var today = new Date(); if(new Date($(this).va

我正在尝试验证日期输入字段。 我可以防止jquery datepicker使用

 $('#delivery_date').datePicker({ minDate: 0 }); 
但用户仍然可以手动输入日期。如何防止或验证这一点

$('#交货日期')。在('change',function(){
$('#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());
});
var today=新日期(); if(new Date($(this.val())
谢谢各位……我会尝试这些。作为一种临时措施,我将日期输入字段设置为只读……输入日期的唯一方法是使用datepicker进行拾取。在date picker中,我已禁用了过去的日期。请记住,所有客户端代码都可以被传递和覆盖。您必须复制验证服务器端以确保数据完整性-client端验证仅为用户方便。您好,您能否确认maxDate正在工作,因为它不适用于我,($(“#交货日期”)。datePicker({startDate:'01/01/1970',maxDate:+5”})对日期选择没有任何影响,因为我可以选择任何日期。
// 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());
    }
})