Groups | Blog | Home
all groups > asp.net > february 2007 >

asp.net : validating date of birth


Eugene Anthony
2/11/2007 11:01:10 PM
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

Alexey Smirnov
2/11/2007 11:32:41 PM
[quoted text, click to view]

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);
AddThis Social Bookmark Button