Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried with this code...



C#
function IsValidDateTime(Day, Mn, Yr) {
        var DateVal = Day + "/" + Mn + "/" + Yr;
        var dt = new Date(DateVal);

        if (dt.getDate() != Day) {
            alert('Invalid Date');
            return (false);
        }
        else if (dt.getMonth() != Mn) {
            //this is for the purpose JavaScript starts the month from 0
            alert('Invalid Date');
            return (false);
        }
        else if (dt.getFullYear() != Yr) {
            alert('Invalid Date');
            return (false);
        }


        return (true);
    }



Here it's working fine...i mean it cannot enter type of charaters from the keyboard,but if i delete the number.. then it shows an exption means date format is not correct..so...i want to enter date from calender..but no modifications from the key board..please help me
Posted
Updated 5-Jan-14 17:19pm
v2
Comments
Karthik_Mahalingam 5-Jan-14 9:39am    
best way to validate the textbox is ononblur event...
Siva Hyderabad 5-Jan-14 9:46am    
i tried with "read only" properity of textbox..then it goes another
page.
Kornfeld Eliyahu Peter 5-Jan-14 9:48am    
Why not use jQuery and one of it's extension for validating?
Maciej Los 5-Jan-14 11:23am    
Not clear! Please, be more specific and provide more details about your issue.
Jameel VM 5-Jan-14 12:49pm    
make your textbox as readonly

1 solution

Alternative approach: Explore the DatePicker[^]. This will do the right validations for you.
 
Share this answer
 
v2

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