• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 756
  • Last Modified:

ValidationExpression for dd-MMM-yyyy including leap years

Hi I have the following below. Its just a sample. I want the validatior to alert when 30-Feb entered and also alert when 29-Feb entered when not a leap year.

This question under the accepted solution has it for the format  ddmmyyyy.
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22806356.html?sfQueryTermInfo=1+leap+valid+year


Could anyone help?
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><img id="btn" src="Images/calendar.png" />
    <cc1:CalendarExtender PopupButtonID="btn" Format="ddMMyyyy" TargetControlID="TextBox1" ID="cal" runat="server"></cc1:CalendarExtender>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
        ControlToValidate="TextBox1" ErrorMessage="Not a valid date" 
        ValidationExpression="">
    </asp:RegularExpressionValidator>

Open in new window

0
caoimhincryan
Asked:
caoimhincryan
  • 3
  • 2
1 Solution
 
Gyanendra SinghArchitectCommented:
use this

 ^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$

This patteren accepts '.' '-' and '/'
0
 
caoimhincryanAuthor Commented:
That works good but would you have an expression that allows it for dd-MMM-yyyy i.e- 13-Nov-2008. I have the wrong format in my code snippet above. Sorry about that.
0
 
Gyanendra SinghArchitectCommented:
ohh you want word ... let me try
0
 
caoimhincryanAuthor Commented:
Any luck BondinASP?
0
 
caoimhincryanAuthor Commented:
^((31(?!([-])(Feb(ruary)?|Apr(il)?|June?|(Sep(?=\b|t)t?|Nov)(ember)?)))|((30|29)(?!([-])Feb(ruary)?))|(29(?=([-])Feb(ruary)?([-])(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])([-])(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\b|t)t?|Nov|Dec)(ember)?)([-])((1[6-9]|[2-9]\d)\d{2})$

I think i may have solved it. This has the format dd-MMM-yyyy and also checks for leap years and months that don't have 31 days.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now