How can I use ASP.net asp: RangeValidator to validate the date correctly?

Here's my code:

<asp:TemplateField HeaderText="* License Setup Date">
    <EditItemTemplate>
        <asp:RequiredFieldValidator ID="LicenseSetupDateRequired" 
            ErrorMessage="License Setup Date can't be blank."
            ValidationGroup="EditClientDetails" 
            ControlToValidate="BeginDate"  
            Text="*!" 
            Display="Dynamic" 
            runat="server"></asp:RequiredFieldValidator>                    
        <asp:RangeValidator ID="LicenseSetupDateRange" 
            ErrorMessage="License Setup Date needs to be a date between 01/01/2000 and 12/31/2200"
            ValidationGroup="EditClientDetails" 
            ControlToValidate="BeginDate"
            MinimumValue="01/01/2000"
            MaximumValue="12/31/2002"
            Type="Date"
            Text="*!" Display="Dynamic" runat="server"></asp:RangeValidator>                        
        <asp:TextBox ID="BeginDate" MaxLength="10" 
            Text='<%# Bind("BeginDate", "{0:MM/dd/yyyy}") %>' 
            runat="server"></asp:TextBox>
        <span class="fieldNote">(mm/dd/yyyy format)</span>
    </EditItemTemplate>
</asp:TemplateField>

      

And the results:

  • 01/01/2008 Fails
  • 02/02/2008 Fails
  • 11/11/2000 Skips
  • 08/08/2001 Skips

What am I missing here?

+1


source to share


2 answers


You need to increase the MaximumValue to a date that is greater than your tests. In particular, MaximumValue should be set to 12/31/2200. You have the maximum value.



+1


source


There is a typo in the example you gave. You define MaximumDate as ' 31/12/2002 ' instead << → 31/12/2200.



+1


source







All Articles