validating date of birth

  • Thread starter Thread starter Eugene Anthony
  • Start date Start date
E

Eugene Anthony

I tried validating my dob using the code bellow however I keep getting
the message "Enter a valid dob" despite entering a valid dob.


String dob = TextBox6.Text + "/" + TextBox7.Text + "/" + TextBox8.Text;

try
{
DateTime dt = DateTime.Parse(dob);
}
catch (FormatException)
{
Label9.Text = "Enter a valid dob";
return;
}


How do I solve the problem?


Your help is kindly appreciate.


Eugene Anthony
 
I tried validating my dob using the code bellow however I keep getting
the message "Enter a valid dob" despite entering a valid dob.

String dob = TextBox6.Text + "/" + TextBox7.Text + "/" + TextBox8.Text;

try
{
DateTime dt = DateTime.Parse(dob);}

catch (FormatException)
{
Label9.Text = "Enter a valid dob";
return;

}

How do I solve the problem?

Which culture settings do you have?

Try this

System.Globalization.CultureInfo culture = new
System.Globalization.CultureInfo("en-GB"); // change it to you culture
DateTime a =
DateTime.Parse("18/09/2004",culture,System.Globalization.DateTimeStyles.NoCurrentDateDefault);
 
Back
Top