Solved

Regular Expression not working

Posted on 2013-01-31
6
267 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 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

16 Experts available now in Live!

Get 1:1 Help Now