Have a careful look at your expression: you will see that it is divided into three parts: the first part (0[1-9]|1[012])
matches months (from 01 to 12), the second part (0[1-9]|[12][0-9]|3[01])
matches days (from 01 to 31), while a last part (19|20)\d\d+
matches years (from 1900 up). Finally, [- /.]
matches your separators (-
or .
) and ^
and $
match string beginning and string end, respectively.
I want to add two more observations:
- Usually (in my experience, mainly web) the escape character (used in your expression before
.
is \
rather than /
- At the end of your expression you have
(19|20)\d\d+
: this will maths 1900
but will also match 190000 (because of the + sign).
Given this, I would change your regexp as follows:
^(0[1-9]|[12][0-9]|3[01])[- \.](0[1-9]|1[012])[- \.](19|20)\d{2}$
note however that this regexp will match also non-valid dates as for example 30th of February.
If you need something more accurate have a look here: Regex to validate date format dd/mm/yyyy