Validatte date formate using javascript

html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
        <title></title>
        <script type="text/javascript">
            function IsValidDate(myDate) {
                var filter = /^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][bB]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][u]l|[aA][Uu][gG]|[Ss][eE][pP]|[oO][Cc]|[Nn][oO][Vv]|[Dd][Ee][Cc])-(19|20)\d\d$/
                                return filter.test(myDate);
            }
            function test() {
        

            var txtTest = document.getElementById('<%=txtTest.ClientID%>');
            if(txtTest.value!="")
            {
            var isValid = IsValidDate(txtTest.value);
            if (isValid) {
               
            }
            else {
              
                
                
alert('Incorrect format');
 document.getElementById('<%=txtTest.ClientID%>').value="";
            }
            return isValid
            }
            return false;
        }

        </script>
</head>
<body>
        <asp:TextBox ID="txtTest" runat="server" Width="95px" TabIndex="6" onblur="return test();" ></asp:TextBox>
                                                <ajaxToolkit:CalendarExtender ID="calDateTime"  
                                                    runat="server" Format="dd-MMM-yyyy" TargetControlID="txtTest">
                                                </ajaxToolkit:CalendarExtender>

</body>

0 comments:

Post a Comment