Click here to Skip to main content
11,922,641 members (33,168 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked

Validating dates in dd-MMM-yyyy format

, 3 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
using System.Text.RegularExpressionsprivate void fnValidateDateFormat(string strStartDate,string strEndDate){ Regex regexDt = new...
using System.Text.RegularExpressions
private void fnValidateDateFormat(string strStartDate,string strEndDate)
	Regex regexDt = new Regex("(^(((([1-9])|([0][1-9])|([1-2][0-9])|(30))\\-([A,a][P,p][R,r]|[J,j][U,u][N,n]|[S,s][E,e][P,p]|[N,n][O,o][V,v]))|((([1-9])|([0][1-9])|([1-2][0-9])|([3][0-1]))\\-([J,j][A,a][N,n]|[M,m][A,a][R,r]|[M,m][A,a][Y,y]|[J,j][U,u][L,l]|[A,a][U,u][G,g]|[O,o][C,c][T,t]|[D,d][E,e][C,c])))\\-[0-9]{4}$)|(^(([1-9])|([0][1-9])|([1][0-9])|([2][0-8]))\\-([F,f][E,e][B,b])\\-[0-9]{2}(([02468][1235679])|([13579][01345789]))$)|(^(([1-9])|([0][1-9])|([1][0-9])|([2][0-9]))\\-([F,f][E,e][B,b])\\-[0-9]{2}(([02468][048])|([13579][26]))$)");
	Match mtStartDt = Regex.Match(strStartDate,regexDt.ToString());
	Match mtEndDt 	= Regex.Match(strEndDate,regexDt.ToString());
	if (mtStartDt.Success && mtEndDt.Success)
      		//piece of code
Above regular expression is specific to dates in dd-MMM-yyyy format. In case you are using more than 1 date format across your application, it would be a good idea to declare either a switch case that returns specific regex objects as per date formats or enums.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMinimally, if you're not going to go with Luc's suggestion, ... Pin
TheyCallMeMrJames18-May-10 9:02
memberTheyCallMeMrJames18-May-10 9:02 
GeneralRe: Minimally, if you're not going to go with Luc's suggestion, ... Pin
PIEBALDconsult4-Jun-12 17:08
memberPIEBALDconsult4-Jun-12 17:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151125.1 | Last Updated 3 Jul 2011
Article Copyright 2010 by girlprogrammer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid