locked
check textbox dateformat in javascript without postback RRS feed

  • Question

  • User-807418713 posted

    Hello

    In aspx page i have one textbox1

    for example in that textbox im using format like this dd-MMM-yyyy example 01-Oct-2020 if user anything apart from this i want to show date format is not correct without postback..

    how to do so 

    Thanking you

    Wednesday, October 7, 2020 4:57 PM

Answers

  • User-939850651 posted

    Hi Gopi.MCA,

    According to your description, I think you could try to use Moment.js to verify the date format of the value in the text box.

    A simple example:

    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.5.1.min.js"></script>
        <script src="Scripts/moment.min.js"></script>
        <script>
            function change() {
                console.log(moment($('#date').val(), 'DD-MMM-YYYY', true).isValid());
    //do something here } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox runat="server" ID="date" onchange="change()"></asp:TextBox> </div> </form> </body>

    Result:

    Hope this can help you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 8, 2020 8:40 AM