日期验证在某些情况下不起作用

问题描述

我希望以这种方式验证日期,以便距昨天仅3个月的日期 即DATE应该是> = 3个月,且

我得到了想要的输出,但是在警报消息其当天的设置之后,无论用户选择什么。即使我提到了return false;添加" UserDate = new Date();",但它未将“ UserDate”设置为当前日期。为什么它不起作用。请帮我。任何人都可以帮助我 在此先感谢

代码

<asp:TextBox ID="txtdate" AutoComplete="off" placeholder="Enter Sales Date" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender" OnClientDateSelectionChanged="TDate"
runat="server" TargetControlID="txtdate" Format="dd-MMM-yyyy"></ajaxToolkit:CalendarExtender>
      <script type="text/javascript">
        function TDate() {
        var UserDate = document.getElementById("txtdate").value;
        var ToDate = new Date();
        var minDate = new Date().setMonth(new Date().getMonth() - 3);
        if (new Date(UserDate) > ToDate || new Date(UserDate) < new Date(minDate)) {
             alert('Selection date should be within 3 month from yesturday');
                 return false;
                    }
              return true;
                }
       </script>

After clicking "OK" its again selected 29th date which i don't want i want to select select Yesterday date by default

解决方法

此功能仅在引导日期选择器中启用从当前日期开始的三个月。

var lastDate = new Date(today.getFullYear(),today.getMonth()+3,today.getDate());


$("#startdate").datepicker({
  isDisabled: function(date) {
    return date.valueOf() < Date.now() ? false : true;
  },startDate: "dateToday",// If you need to disable past dates
  autoClose: true,viewStart: 0,weekStart: 1,endDate: lastDate,dateFormat: "dd/mm/yyyy"
});