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. Advertising

  2. tshad

    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

    tshad wrote:
    > 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
     
    , May 23, 2005
    #2
    1. Advertising

  3. tshad

    shekharshete_2005

    Joined:
    Aug 16, 2011
    Messages:
    1
    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. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tarun Mistry

    Todays date in range validator?

    Tarun Mistry, Feb 21, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    12,024
    Tarun Mistry
    Feb 22, 2006
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,270
    Michael Borgwardt
    May 30, 2004
  3. Replies:
    46
    Views:
    971
    Antoon Pardon
    Jul 25, 2006
  4. Lambda
    Replies:
    2
    Views:
    399
    James Kanze
    Jul 16, 2008
  5. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    153
    Tomoyuki Kosimizu
    Nov 27, 2003
Loading...

Share This Page