Range validator for date

Discussion in 'ASP .Net' started by tshad, May 23, 2005.

  1. tshad

    tshad Guest

    I have been trying to set up a range validator and regular expression for my
    dates.

    I tried this:

    <asp:RangeValidator runat="server"
    ControlToValidate="AbsentFrom1"
    MinimumValue="12/31/1950"
    MaximumValue="1/1/2100"
    Type="Date" text="Invalid Date"/>

    Which doesn't seem to work at all.

    I put in 1/15/1940 and it didn't give me an error.

    I need this because my regular expression won't handle leap years and I
    don't want to have to deal with different type of years over and about 2 or
    4 characters. My RegularExpressionValidator (which does work) is:

    <asp:RegularExpressionValidator ControlToValidate="AbsentFrom1"
    ValidationExpression="^(([1-9])|(0[1-9])|(1[0-2]))\/(([1-9])|(0[1-9])|(1[0-9
    ])|(2[0-9])|(3[0-1]))\/((\d{2})|(\d{4}))$" Display="Dynamic" Text="<br>From
    Date Invalid or in wrong Format(MM/DD/YY)" runat="server"/>

    Why doesn't the range validator work?

    Is there a better way to validate my dates?

    Thanks,

    Tom
     
    tshad, May 23, 2005
    #1
    1. Advertisements

  2. tshad

    dan.c.roth Guest

    Hi

    Use CompareValidator for that date type and RangeValidator for the
    range like so:

    <asp:CompareValidator id="CompareValidator1" runat="server"
    ErrorMessage="CompareValidator" Type="Date"
    ControlToValidate="TextBox1"
    Operator="DataTypeCheck"></asp:CompareValidator>
    <asp:RangeValidator id="RangeValidator1" runat="server"
    ErrorMessage="RangeValidator" MaximumValue="2010-01-01"
    MinimumValue="2009-01-01"
    ControlToValidate="TextBox1">RangeValidator</asp:RangeValidator>
    <asp:TextBox id="TextBox1" runat="server">2010-01-01</asp:TextBox>

    Regards,

    Daniel Roth
    MCSD.NET
     
    dan.c.roth, May 23, 2005
    #2
    1. Advertisements

  3. tshad

    shekharshete_2005

    Joined:
    Aug 16, 2011
    Messages:
    1
    Likes Received:
    0
    Validate Date using Range Validator

    Hi,
    I want to validate the Date using Range Validator with min val:01/01/1900 and max value with 01/01/1993 to calculate at least 18yr old for voting!
    The date is in MM/DD/YYYY but i get the Error how to do?

    Plz help!
    Shekhar Shete,INDIA
    MCTS
     
    shekharshete_2005, Aug 16, 2011
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.