raklos
raklos

Reputation: 28545

why is my date validator not working?

I'm trying to validate a date entered into text boxes like so using a custom validator:

string CombinedDate = String.Format("{0}-{1}-{2}", txtDay.Text, txtMonth.Text, txtYear.Text);

if (DateTime.TryParseExact(CombinedDate, "dd-MM-YYYY", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out date))
{
    args.IsValid = true;
}
else
{
    args.IsValid = false;
}

but it fails for 21-02-2005 why is that? and how can i fix it

Upvotes: 2

Views: 162

Answers (1)

Arcturus
Arcturus

Reputation: 27055

YYYY must be yyyy

See here for other formats from MSDN

Upvotes: 6

Related Questions