validating date of birth

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
 
G

Guest

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top