Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to validate date in a textbox in asp.net in format mm.dd.yyyy
Posted

try this if you want to validate textBox

XML
bool isValid = true;
        try
        {
            string dt = TextBox1.Text;
            DateTime dateTime = DateTime.ParseExact(dt, "MM.dd.yy", System.Globalization.CultureInfo.InvariantCulture);
        }
        catch
        {
            this.Response.Write("Invalid Date entered<br>");
            isValid = false;
        }
        this.Response.Write("isValid: " + isValid + "<br>");
 
Share this answer
 
Comments
Sachin gulati 27-Aug-11 6:01am    
thanx alot... it works.... thank u :)
Mahendra.p25 27-Aug-11 6:10am    
No need to say Thanks.
validating the date is will not work properly in all the situations .
its better to use ajax calender extender in that mention the format ...
hope it helps you
 
Share this answer
 
Comments
Sachin gulati 27-Aug-11 5:05am    
yeah that is true it doesn't work in all situation....
i try to use ajax calender extender as u suggested....
thanx.... :)

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