locked
Date validation RRS feed

  • Question

  • User66371569 posted
    I have 2 textboxes dates From / to

    My format MMM-yyyy
    I want when i insert in From
    Jan-2016 and in To Feb-2012

    Error shows 'you cant insert in date to year less than date from'
    Monday, January 21, 2019 8:35 AM

All replies

  • User-1174608757 posted

    Hi  thepast,

     According to your description,I have made a sample here. I suggest you could use jquery to get the value of textbox ,than change the type as date and compare the two dates.

    Here is my demo, I hope it could help you.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                $("#Button1").click(function () {
                    var fdate = new Date($("#Text1").val());
                    var ldate = new Date($("#Text2").val());
                    if (fdate.getTime() >= ldate.getTime()) {
    
                        alert("you can't insert in date to year less than date from")
                    }
    
                })
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
              from:<input id="Text1" type="text" />
                to:<input id="Text2" type="text" />
                <input id="Button1" type="button" value="button" />
            </div>
        </form>
    </body>
    </html>
    

     It shows as below:

    Best Regards

    Wei Zhang

    Tuesday, January 22, 2019 2:15 AM