Click here to Skip to main content
Click here to Skip to main content

Tagged as

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

Comments and Discussions

GeneralMinimally, if you're not going to go with Luc's suggestion, ... PinmemberTheyCallMeMrJames18-May-10 9:02 
GeneralRe: Minimally, if you're not going to go with Luc's suggestion, ... PinmemberPIEBALDconsult4-Jun-12 17:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web02 | 2.8.150224.1 | Last Updated 3 Jul 2011
Article Copyright 2010 by girlprogrammer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid