I've googled up a lot of regexes to validate dates in DD.MM.YYYY format. Like this one:
(0[1-9]|1[0-9]|2[0-8]|(?:29|30)(?!.02)|29(?=.02.\d\d(?:[02468][048]|[13579][26]))|31(?=.0[13578]|.1[02]))(?:\.(?=\d\d\.)|-(?=\d\d-)|\/(?=\d\d\/))(0[1-9]|1[0-2])[.\/\-]([1-9][0-9]{3})
and it works fine.
As far as I understand the ([1-9][0-9]{3})
part refers to year. I tried removing it and it started validating dates ending with dots, like 01.05.
, 10.07.
etc.
>>> regex = '^(0[1-9]|1[0-9]|2[0-8]|(?:29|30)(?!.02)|29(?=.02.\d\d(?:[02468][048]|[13579][26]))|31(?=.0[13578]|.1[02]))(?:\.(?=\d\d\.)|-(?=\d\d-)|\/(?=\d\d\/))(0[1-9]|1[0-2])[.\/\-]$'
>>> aaa = '12.02.'
>>> bbb = '32.02.'
>>> print(re.match(regex, aaa))
<_sre.SRE_Match object; span=(0, 6), match='12.02.'>
>>> print(re.match(regex, bbb))
None
But when I remove the part that takes care of the dot/dash divider
[.\/\-]
it doesn't validate dates without the trailing dots:
>>> regex = '^(0[1-9]|1[0-9]|2[0-8]|(?:29|30)(?!.02)|29(?=.02.\d\d(?:[02468][048]|[13579][26]))|31(?=.0[13578]|.1[02]))(?:\.(?=\d\d\.)|-(?=\d\d-)|\/(?=\d\d\/))(0[1-9]|1[0-2])$'
>>> aaa = '12.02'
>>> bbb = '32.02'
>>> print(re.match(regex, aaa))
None
>>> print(re.match(regex, bbb))
None
How do I make this work?
UPDATE ABOUT FEB 28 / FEB 29:
It's okay if it won't validate 28/29 Feb, this is acceptable in my case.
UPDATE ABOUT PYTHON:
I cannot use python validation for this, sadly it's only a regex field in a web form that I can use.