Need regular expression for validating date in dd-MMM-yyyy format

Using a DatePicker is probably the best approach. However, since that's not what you asked, here's an option (although it's 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's a place you can easily test Regular Expressions: http://www.regular-expressions.info/javascriptexample.html


It's not regex, but you can use build in DateTime.TryParseExact function to validate your datetime string

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

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

Regex without leading zero in day.

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

Update Regex with leading zero in day.

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

Tags:

Asp.Net

Regex