Solved

Regular Expression not working

Posted on 2013-01-31
6
283 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# winforms programmitically move panels 6 43
defining NULL or 0 10 44
ASP.NET (VB) return a record 2 35
Adding items to a C# list incrementally 5 29
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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