Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
JavaScript
function ValidateDate(txt, keyCode)
        {
            if(keyCode==16)
                isShift = false;
            var val=txt.value;
            var lblmesg = document.getElementById("<%=lblMesg.ClientID%>") ;
            if(val.length == 10)
            {
                var splits = val.split("/");
                var dt = new Date(splits[1] + "/" + splits[0] + "/" + splits[2]);

                //Validation for Dates
                if(dt.getDate()==splits[0] && dt.getMonth()+1==splits[1] && dt.getFullYear()==splits[2])
                {
                    lblmesg.style.color="green";
                    lblmesg.innerHTML = "Valid Date";
                }
                else
                {
                    lblmesg.style.color="red";
                    lblmesg.innerHTML = "InValid Date";
                    return;
                } 

                //Range Validation
                if(txt.id.indexOf("txtRange") != -1)
                    RangeValidation(dt);

                //BirthDate Validation
                if(txt.id.indexOf("txtBirthDate") != -1)                
                    BirthDateValidation(dt)
            }
            else if(val.length < 10)
            {
                lblmesg.style.color="blue";
                lblmesg.innerHTML = "Required dd/mm/yy format. Slashes will come up automatically.";
            }
}


ASP.NET
 <asp:TextBox ID="txtValidate" runat="server" MaxLength = "10" onkeyup = "ValidateDate(this, event.keyCode)" onkeydown = "return DateFormat(this, event.keyCode)"></asp:TextBox> 

I want to include a slash within a TextBox for typing a Date.. I don't want it to generate a slash while typing...it should be static when the page is loaded.... Is it possible to do that without using AjaxToolkit ???
Posted
Updated 13-Nov-14 23:24pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900