2012-05-09 91 views
0

如何限制用户输入未来日期?jquery 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; } 

还有什么需要被writen? Range属性也不起作用。感谢您的帮助。

+0

你尝试过使用的minDate和/或的maxDate? maxDate:0可能会诀窍。 http://jqueryui.com/demos/datepicker/#min-max – SpaceBison

+0

[检查这个答案] [1] [1]:http://stackoverflow.com/questions/4002781/jquery-ui日期选择器未来日期 –

回答

1

要禁用将来的日期添加:

maxDate: new Date, 
+0

感谢您的答复,但我仍然能够选择未来的日期。 我想: 的maxDate:新的日期 的maxDate:“0” 的maxDate:“+ 1D” 是否有书面的选项或必须的maxDate之前写了一些其他必要的选项中的任何特定的顺序? –

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.