You need a regular expression to check the date in the format dd-MMM-yyyy

I am not good at writing regular expressions, so you need your help. I want to confirm the date in the format "dd-MMM-yyyy", i.e. 07-Jun-2012. I am using RegularExpressionValidator in asp.net.

Can someone help me provide an expression?

Thank you for sharing your time.

+7
source share
8 answers

Using DatePicker is probably the best approach. However, since this is not what you requested, here is an option (although it is case sensitive):

^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$

In addition, here you can easily test regular expressions: http://www.regular-expressions.info/javascriptexample.html

+24
source

.

^\d{1,2}-[a-zA-Z]{3}-\d{4}$

.

^\d{2}-[a-zA-Z]{3}-\d{4}$
+7

, DateTime.TryParseExact datetime

DateTime dateTime;
string toValidate = "01-Feb-2000";

bool isStringValid = DateTime.TryParseExact(
    toValidate,
    "dd-MMM-yyyy",
    CultureInfo.InvariantCulture,
    DateTimeStyles.None,
    out dateTime);
+3

"00" , :

^(([1-9])|([0][1-9])|([1-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$

/:

1. . . "DEC" , "Dec" . ( ).

2. , , , 30 , 31 ..

+1

- ( user1441894):

var x = DateTime.Parse("30-Feb").GetDateTimeFormats();

I learned to use it yesterday (for another purpose). So try this instruction to review the validity / invalidity of a date :)

0
source
"^(([1-9]|0[1-9]|1[0-9]|2[1-9]|3[0-1])[-]([JAN|FEB|MAR|APR|MAY|JUN|JULY|AUG|SEP|OCT|NOV|DEC])[-](d{4}))$"
0
source
"\d{4}\d{2}\d{2}|\d{2}/\d{2}/\d{4}|\d{2}.\d{2}.\d{4}|\d{2}\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)|(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2}\-\d{4}|\d{4}-\d{2}-\d{2}"

This format mm.dd.yyyy, d-MMM,mm.dd.yyyy

0
source
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
    }
}
-1
source

All Articles