Validate date - User should select only next month data from today's date

Validate date - User should select only next month data from today's date

Hi,

I have a date field to which, I want the user to select only dates from next month from today's date. The date field is in MM/DD/YYYY format.

I tried the below code, but it is not working

  1. var validflag = true;
         var msg = "Please provide a valid details for the below: ";
         var isMessaged = false;
         var inputStartDate ="";
    var dtStartDate = $("input[title='My Start Date']").val();
  2. var todaysDate = new Date();
  3.  var newtodaysDate = todaysDate.setMonth(todaysDate.getMonth() + 1);
  4. if(dtStartDate.length > 0) {
  5. inputStartDate = new Date(dtStartDate);
  6. var newinputStartDate = new Date(dtStartDate.setMonth(dtStartDate.getMonth() + 2));
  7. // call setHours to take the time out of the comparison
  8. if( (inputStartDate.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0)) || (inputStartDate < todaysDate ) || (newtodaysDate > newinputStartDate.getTime() ) )
  9. {
  10. // StartDate equals today's date or Date is in the Past
  11.  msg = msg + "<br/> Start Date should be greater than Today's Date and should have 1 month gap";
  12. isMessaged = true;
  13. validflag = false;
  14. }
  15. }
  16.  

    I am getting the error as "Object doesn't support property or method 'getMonth' "

  17. How to fix this?

  18. Thanks