jquery datepicker验证

时间:2012-05-09 10:56:16

标签: jquery validation datepicker

如何限制用户输入将来的日期?

这是观点:

@Html.TextBoxFor(a => a.ARRIVING_DT,new { @class="date"})

$(".date").datepicker({   
    changeMonth: true,   
     changeYear: true,   
     dateFormat: 'dd/mm/yy' ,
     selectOtherMonths: true,
        showOtherMonths: true,
        showStatus: true,
        showButtonPanel: true,
        showOn: 'button',
        buttonImage: '../../Content/themes/base/images/i_cal.gif',
        buttonImageOnly: true,
        buttonText: 'Choose a Date'
          }); 

我正在尝试将valdation属性写为:

    [Required(ErrorMessage = "Enter Date of Departure")]
    public object DEPARTURE_DT { get; set; } 

还需要写什么? Range属性也不起作用。感谢您提供任何帮助。

2 个答案:

答案 0 :(得分:1)

要停用将来的日期,请添加:

maxDate: new Date,

答案 1 :(得分:1)

$('#<%= txtDate.ClientID  %>').datepicker({
                 maxDate: new Date(currentYear, currentMonth, currentDate)
             });
This will disable the future dates from getting entered. another best way for the question.