Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > validation expression for date

Reply
Thread Tools

validation expression for date

 
 
Amir Steta
Guest
Posts: n/a
 
      10-03-2007
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



 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      10-03-2007
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


 
Reply With Quote
 
 
 
 
Amir Steta
Guest
Posts: n/a
 
      10-04-2007
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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date Validation Expression and Leap Year Hai Nguyen ASP .Net 1 02-27-2004 11:18 AM
reg expression for date validation Brian Henry ASP .Net 1 12-05-2003 09:23 PM



Advertisments