regex to validate date in DD.MM format
<p>I've googled up a lot of regexes to validate dates in DD.MM.YYYY format. Like this one:</p>

<p><code>(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})</code></p>

<p>and it works fine. </p>

<p>As far as I understand the <code>([1-9][0-9]{3})</code> part refers to year. I tried removing it and it started validating dates ending with dots, like <code>01.05.</code>, <code>10.07.</code> etc.</p>

<pre><code>&gt;&gt;&gt; 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])[.\/\-]$'
&gt;&gt;&gt; aaa = '12.02.'
&gt;&gt;&gt; bbb = '32.02.'
&gt;&gt;&gt; print(re.match(regex, aaa))
&lt;_sre.SRE_Match object; span=(0, 6), match='12.02.'&gt;
&gt;&gt;&gt; print(re.match(regex, bbb))
None
</code></pre>

<p>But when I remove the part that takes care of the dot/dash divider</p>

<pre><code>[.\/\-]
</code></pre>

<p>it doesn't validate dates without the trailing dots:</p>

<pre><code>&gt;&gt;&gt; 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])$'
&gt;&gt;&gt; aaa = '12.02'
&gt;&gt;&gt; bbb = '32.02'
&gt;&gt;&gt; print(re.match(regex, aaa))
None
&gt;&gt;&gt; print(re.match(regex, bbb))
None
</code></pre>

<p>How do I make this work?</p>

<p><strong>UPDATE ABOUT FEB 28 / FEB 29:</strong></p>

<p>It's okay if it won't validate 28/29 Feb, this is acceptable in my case.</p>

<p><strong>UPDATE ABOUT PYTHON:</strong></p>

<p>I cannot use python validation for this, sadly it's only a regex field in a web form that I can use. </p>

<p>Just make the dot and year optional:</p>

<pre><code>(?:[.\/\-]([1-9][0-9]{3}))?
</code></pre>

python regex