Solved

Regular Expression not working

Posted on 2013-01-31
6
257 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
6 Comments
 
LVL 25

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 25

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 74

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now