Lets Have a fun with Technology.


Follow by Email

Friday, October 24, 2008

ASP.NET Regular Expression for date format

In ASP.Net Many times required to Validate Date Fromat Enter in Control.
in Regular Expression Following RE used to Validate Date Format.

dd/mm/yyyy Format In regular Expression    (optional mm,optional dd)
([1-9]|0[1-9]|[12][0-9]|3[01])[- /.]([1-9]|0[1-9]|1[012])[- /.][0-9]{4}$

mm/dd/yyyy   (optional mm,optional dd)
^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.][0-9]{4}$

mm/dd/yyyy  (Exact Format)

Prev Post                                                      All Post                                                           Next Post


  1. this expression fails for

    mm/dd/yyyy (Exact Format)

    --> 12/32/2008 date
    Please check and confrim

  2. This isn't a date validation, it's just a validation that dd is between 01 and 31. However, we all know (I hope) the number of days in a month differs both with the month and the year.

    To work it has to be combined with some date-time parsing or conversion of some kind...