2012-05-09 88 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.