ASP.NET RangeValidator for date of birth with culture fr-BE

313 Views Asked by At

I have an ASP.NET web forms application with a textbox for entering the date of birth. There is a RangeValidator for the date of birth.

<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Please enter a valid date of   birth." Display="Dynamic" ControlToValidate="txtDate" Type="Date" />

In the code behind I set the minimum and maximum allowed values like this:

RangeValidator1.MinimumValue = new DateTime(1900, 1, 1).ToShortDateString();
RangeValidator1.MaximumValue = DateTime.Now.ToShortDateString();

This usually seems to work fine. However, a user has set his culture to fr-BE. This culture uses only two digits for the year. The minimum value then becomes "01-01-00" which the range validator interprets as 1st January 2000. Therefore the user cannot enter a date of birth before 2000.

How can I set the range validator's minimum value so that it works correctly for all cultures?

1

There are 1 best solutions below

0
Shimmy Weitzhandler On

Looks like someone had this kind of trouble before.

In the page set the property MinimumValue like the following: ' />