validation expression for date

Discussion in 'ASP .Net Web Controls' started by Amir Steta, Oct 3, 2007.

  1. Amir Steta

    Amir Steta Guest

    I need regular validation expression in order to check entry of date in
    "european" format i.e. 24.09.2007 . Anybody could help?
    So far I have simple expression like this

    (\d{2}\.)(\d{2}\.)(\d{4})

    This expression does not prevent entry of 45.23.2006 for example
     
    Amir Steta, Oct 3, 2007
    #1
    1. Advertising

  2. Hello Amir,

    > I need regular validation expression in order to check entry of date
    > in
    > "european" format i.e. 24.09.2007 . Anybody could help?
    > So far I have simple expression like this
    > (\d{2}\.)(\d{2}\.)(\d{4})
    >
    > This expression does not prevent entry of 45.23.2006 for example



    If you need more fancy validation, either have alook at Peter's Data package
    (http://www.peterblum.com/) or resort to server side validation.

    There are also regular expressions which will in fact match a perfect date
    including leap years and other variations, but they are so large and usually
    in the US format that it will take quite a bit of knowledge of regular expressions
    to rework them. You might be lucky and find what you're looking for in the
    Regular Expression Library (http://www.regexlib.net/). I'd reccommend against
    them as in my experience, you will need to support alternative formats in
    the future. Having one regex will be a serious problem by then.

    --
    Jesse Houwing
    jesse.houwing at sogeti.nl
     
    Jesse Houwing, Oct 3, 2007
    #2
    1. Advertising

  3. Amir Steta

    Amir Steta Guest

    Thank you Jesse, for trying to help. Before posting here I have already
    checked regexlib.com with no success. But today I took Alessandro Olivi
    pattern and corrected it a little bit. So I have following pattern working
    very well

    ^(((0[1-9]|[12][0-9]|3[01])([.])(0[13578]|10|12)([.])(\d{4}))|(([0][1-9]|[12][0-9]|30)([.])(0[469]|11)([.])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([.])(02)([.])(\d{4}))|((29)(\.)(02)([.])([02468][048]00))|((29)([.])(02)([.])([13579][26]00))|((29)([.])(02)([.])([0-9][0-9][0][48]))|((29)([.])(02)([.])([0-9][0-9][2468][048]))|((29)([.])(02)([.])([0-9][0-9][13579][26])))

    I am putting current date on page load and limited length of my date text
    field to 10 charachters. So every wrong entry is prevented by regular
    expression validator.
    I think this is "perfect" as much as it can be in case you are not using
    third party controls made to be sold.

    "Jesse Houwing" wrote:

    > Hello Amir,
    >
    > > I need regular validation expression in order to check entry of date
    > > in
    > > "european" format i.e. 24.09.2007 . Anybody could help?
    > > So far I have simple expression like this
    > > (\d{2}\.)(\d{2}\.)(\d{4})
    > >
    > > This expression does not prevent entry of 45.23.2006 for example

    >
    >
    > If you need more fancy validation, either have alook at Peter's Data package
    > (http://www.peterblum.com/) or resort to server side validation.
    >
    > There are also regular expressions which will in fact match a perfect date
    > including leap years and other variations, but they are so large and usually
    > in the US format that it will take quite a bit of knowledge of regular expressions
    > to rework them. You might be lucky and find what you're looking for in the
    > Regular Expression Library (http://www.regexlib.net/). I'd reccommend against
    > them as in my experience, you will need to support alternative formats in
    > the future. Having one regex will be a serious problem by then.
    >
    > --
    > Jesse Houwing
    > jesse.houwing at sogeti.nl
    >
    >
    >
     
    Amir Steta, Oct 4, 2007
    #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. Brian Henry

    reg expression for date validation

    Brian Henry, Dec 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,726
    Kevin Spencer
    Dec 5, 2003
  2. Hai Nguyen

    Date Validation Expression and Leap Year

    Hai Nguyen, Feb 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,346
    Hans Kesting
    Feb 27, 2004
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,358
    Michael Borgwardt
    May 30, 2004
  4. Ken

    Regular Expression Date Validation

    Ken, Jun 27, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    164
    Kenny
    Jun 27, 2003
  5. Paul Keister

    Regular Expression Date Validation

    Paul Keister, Oct 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    293
    Paul Keister
    Oct 7, 2003
Loading...

Share This Page