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

后端 未结 8 1322
不思量自难忘°
不思量自难忘° 2020-12-31 17:57

I am not expert in writing regular expressions so need your help. I want to validate date in \"dd-MMM-yyyy\" format i.e. 07-Jun-2012. I am using RegularExpressionValidator i

8条回答
  •  被撕碎了的回忆
    2020-12-31 18:05

    The accepted solution allows '00' as the day, so here is a fix for that:

    ^(([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}$
    

    Notes/Exceptions:

    1.Be aware of case sensitivity issues. Eg. 'DEC' will not pass while 'Dec' will pass. You may want to convert the regex string and test string to lowercase before testing (if your application allows).

    2.This will not catch days that don't exist, like Feb 30th, June 31st, etc.

提交回复
热议问题