Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 阻止用户在日历ASP阻止的文本框中输入日期_Javascript_C#_Jquery_Asp.net_Calendar - Fatal编程技术网

Javascript 阻止用户在日历ASP阻止的文本框中输入日期

Javascript 阻止用户在日历ASP阻止的文本框中输入日期,javascript,c#,jquery,asp.net,calendar,Javascript,C#,Jquery,Asp.net,Calendar,我有一个文本框,右边有一个日历图标。当我单击图标时,会出现日历,允许用户选择特定日期。在日历中,用户无法选择上一个日期,并且日历从当前日期起被阻止2年 现在我必须验证文本框 如果用户手动输入任何过去的日期,则会出现错误“无效” 日期”-哪个是正确的 但如果用户输入未来日期,即 自当前日期起2年后的日期,系统接受 不对 所以我想验证文本框,这样当用户在日历中输入一个现在可用的日期时,他就会得到一个错误“无效日期”,而我不想要只读文本框 代码 <script type="text/javasc

我有一个文本框,右边有一个日历图标。当我单击图标时,会出现日历,允许用户选择特定日期。在日历中,用户无法选择上一个日期,并且日历从当前日期起被阻止2年

现在我必须验证文本框

  • 如果用户手动输入任何过去的日期,则会出现错误“无效” 日期”-哪个是正确的
  • 但如果用户输入未来日期,即 自当前日期起2年后的日期,系统接受 不对
  • 所以我想验证文本框,这样当用户在日历中输入一个现在可用的日期时,他就会得到一个错误“无效日期”,而我不想要只读文本框

    代码

    <script type="text/javascript">
    
        window.onload = function () {
            var dateToday = new Date();
            $("input.dtpRelease").datepicker({
    
                showOn: 'button',
                changeYear: true,
                changeMonth:true,
                minDate: dateToday,
                maxDate: "2y",
                buttonImageOnly: true,
                dateFormat: "mm/dd/yy",
                buttonImage: '/Images/icon_calendar_24.png',
    
            });
       }
    
    <asp:TextBox ID="dtpStartDate" runat="server" Style="width: 80px; margin-top: 5px;" CssClass="form-control dp2 dtpRelease pull-left" MaxLength="100" placeholder="Start Date" Text='<%# MSEncoder.Encoder.HtmlEncode(Convert.ToString( Eval("FulfillmentStartDate"))) %>' onblur="ValidateDate(this)"></asp:TextBox> 
                               <br/><br/><asp:RegularExpressionValidator ID="regExSDate" runat="server" ControlToValidate="dtpStartDate" ForeColor="Red" Display="Dynamic" ValidationExpression="^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$" ErrorMessage="Please enter date in MM/DD/YYYY Format"  ValidationGroup="vg" ></asp:RegularExpressionValidator>
                                         <asp:CompareValidator ID="cvStartDate" runat="server" ControlToValidate="dtpStartDate" ErrorMessage="Invalid Start Date" ForeColor="Red" Operator="GreaterThanEqual"  Display="Dynamic" ValidationGroup="FirstPreview" CssClass="validatorMsg" ValueToCompare="<%# DateTime.Today.ToShortDateString() %>" SetFocusOnError="True"  Type="Date" ></asp:CompareValidator> 
    
    
    window.onload=函数(){
    var dateToday=新日期();
    $(“input.dtprelese”).datepicker({
    showOn:'按钮',
    变化年:是的,
    变化月:对,
    minDate:dateToday,
    maxDate:“2y”,
    buttonImageOnly:正确,
    日期格式:“mm/dd/yy”,
    buttonImage:“/Images/icon_calendar_24.png”,
    });
    }
    


    为什么只禁用文本框,让用户只通过日期选择器输入日期。
    与此完全相同,但您可以从文本框旁边的图像触发日历

    您可以使用以下功能检查文本框中的日期是否在范围内

    <script>
       function checkDate(d)
       {
           var maxAcceptedDate = new Date()
           maxAcceptedDate.setFullYear(maxAcceptedDate.getFullYear()+2)
    
           return d <= maxAcceptedDate
       }
    </script>
    
    
    功能检查日期(d)
    {
    var maxAcceptedDate=新日期()
    maxAcceptedDate.setFullYear(maxAcceptedDate.getFullYear()+2)
    
    return d您是否使用asp文本框或html输入标记?同时请提供代码以验证我正在使用的html。但是我正在尝试将ascx代码粘贴到此处,但它不接受您是否使用webforms以及是否使用任何asp.net验证程序?Id以便您可以使用我尝试了所有可能的asp验证程序组合,但没有得到我想要的需要。所以发布这个问题,因为这不是我的要求…用户应该能够手动输入日期
    <script>
       function checkDate()
       {
          //var d = [get text from your textbox as date]
           var maxAcceptedDate = new Date()
           maxAcceptedDate.setFullYear(maxAcceptedDate.getFullYear()+2)
    
           return d<=maxAcceptedDate
       }
    </script>