Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
 
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 10-Oct-12 0:46am
Wes101386

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
Try
 
{
   Datetime myDate = Datetime.Parse(someTextBox.Text)
}
 
Catch (Exception ex)
{
 
   'Not a valid Date

'your Msg Goes Hear....
   'Do Something
 
}
  Permalink  
Comments
Wes101 at 10-Oct-12 8:28am
   
thanks alot, it worked first time
vivektiwari97701 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100