Solved

Regular Expression not working

Posted on 2013-01-31
6
295 Views
Last Modified: 2013-02-07
i am using following regular expression validator, but it not working with the date 19-Feb-2013
it is saying invalid date ? But it is validating 19-Feb-2012. Why this issue ? How do i solve ?

/((([0][1-9]|[12][\d])|[3][01])[-\/]((Jan|Mar|May|Jul|Aug|Oct|Dec))[-\/][1-9]\d\d\d)|((([0][1-9]|[12][\d])|[3][0])[-\/]((Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))[-\/][1-9]\d\d\d)|(([0][1-9]|[12][\d])[-\/]((Feb))[-\/][1-9]\d([02468][048]|[13579][26]))|(([0][1-9]|[12][0-8])[-\/]((Feb))[-\/][1-9]\d\d\d)/i
0
Comment
Question by:Varshini S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 334 total points
ID: 38840947
This issue is at the end of the expression:
]))|(([0][1-9]|[12][0-8])[-\/]((Feb))[-\/][1-9]\d\d\d)/i
This allows days of 01-09, 10-18 and 20-28 for non-leap year days in Feb.
Look to change this to [0][1-9]|[1][0-9]|[2][0-8]
0
 
LVL 7

Assisted Solution

by:Beneford
Beneford earned 166 total points
ID: 38840967
re says:
1-31 [Jan|Mar|May|Jul|Aug|Oct|Dec] any year
or
1-30 any month except Feb
or
1-29 Feb any year ending [02468][048] or ending [13579][26]
or
1-28 Feb any year

The problem is the formulation of 1-28 which actually says [12][0-8] which excludes 19.
the 1-28 condition should be
([0][1-9]|[1][0-9]|[2][0-8])

Actually, the formula would probably be better with 1-28 before (just) the 29 Feb logic.
0
 

Author Comment

by:Varshini S
ID: 38841023
Thank you, it is working but if i give the date 29-Feb-2013 - it is not validating. Why ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Accepted Solution

by:
Shaun Kline earned 334 total points
ID: 38841157
Define "not validating". Do you mean it is allowing that date?
0
 

Expert Comment

by:smokinmark
ID: 38841266
www.regexlib.com

has regular expressions for almost anything.  There is one on there that does exactly what you want.  Look under Date/Time.

Cheers.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38841498
Why use a regex for date validation? Why not use a CompareValidator?

e.g.  (http://stackoverflow.com/a/939852/884561)

<asp:CompareValidator
    id="dateValidator" runat="server" 
    Type="Date"
    Operator="DataTypeCheck"
    ControlToValidate="txtDatecompleted" 
    ErrorMessage="Please enter a valid date.">
</asp:CompareValidator>

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question