Click here to Skip to main content
15,891,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I'm having problems validating my date, I got a text box (tbDate) with a jquery calendar drop, but I'm still been told that I must validate that date, I've got the following method but it doesn't seem to be working for me, if there is any other way please advise and help, thanks alot.

C#
DateTime validate;
        if (DateTime.TryParse(tbDOB.Text, out validate))
        {
            update.Parameters.AddWithValue("@dob", tbDOB.Text);

        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Window", "alert('Enter Valid Date');", true);

        }
Posted

1 solution

U Can validate your date Using Javascript with rejex expression

http://www.roseindia.net/answers/viewqa/JavaScriptQuestions/25909-javascript-date-validation-using-regex.html[^]

or if u want to validate in server side just use try.. catch.

VB
Try

{
   Datetime myDate = Datetime.Parse(someTextBox.Text)
}

Catch (Exception ex)
{

   'Not a valid Date

'your Msg Goes Hear....
   'Do Something


}
 
Share this answer
 
Comments
Wes101 10-Oct-12 8:28am    
thanks alot, it worked first time
vivektiwari97701 10-Oct-12 8:34am    
Mark this As Solution.

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