0

How can I restrict the user from entering a future date?

This is the view:

@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'
          }); 

I am trying to write the valdation attribute for this as:

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

What else need to be writen? The Range attribute is also not working. Thanks for any kind of help.

vyegorov
  • 21,787
  • 7
  • 59
  • 73

2 Answers2

1

To disable future dates add:

maxDate: new Date,
Adam
  • 1,684
  • 14
  • 18
  • Thanks for the replies, but still I am able to select a future date. I tried: maxDate: new Date maxDate: '0' maxDate: "+1D" Is there any specific order of writing the options or some other necessary options which must be written before maxDate? – Jasmeet Singh May 10 '12 at 10:06
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.
Deeps23
  • 51
  • 1