The regular expression you used, although it works, it's not very specific. It matches the sequence of these:
\d
= a digit
.+
= one or more of any character
\-
= a literal -
(btw you didn't need the \
here, it has no effect here)
\d{1,2}
= one or two digits
Many non-dates can match this pattern too, for example these strings:
1abcdefg-4
2999999!@$$#$@#$-12
- ...
I would recommend to use a more strict pattern, for example:
\d{4}-\d{2}-\d{2}
This matches the sequence of these:
- exactly 4 digits
- literal
-
- exactly 2 digits
- literal
-
- exactly 2 digits
Note that this is still not perfect. It won't prevent these invalid dates:
A bit more strict pattern would be:
2\d{3}-[01]\d-[0-3]\d
Which, of course, is still not perfect, because it will still allow 2014-19-39
, for example. It's possible to be even more strict, but whether it's worth it / necessary or not depends on your use case.