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)
^([01]\d)/([0-3]\d)/(\d{4})$


Prev Post                                                      All Post                                                           Next Post

Posted in |

3 comments:

  1. Anonymous Says:

    this expression fails for

    mm/dd/yyyy (Exact Format)
    ^([01]\d)/([0-3]\d)/(\d{4})$

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

  2. Hoakz Says:

    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...

  3. Loveneet Chahal Says:

    Good Job

Post a Comment