Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As is mentioned elsewhere, regular expressions almost certanily not what you want. But, having said that, if you really want a regular expression, here is how it is built:</p> <p>31 day months </p> <pre><code>(0[13578]|1[02])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](18|19|20)[0-9]{2} </code></pre> <p>30 day months</p> <pre><code>(0[469]|11)[\/.](0[1-9]|[12][0-9]|30)[\/.](18|19|20)[0-9]{2} </code></pre> <p>February 1-28 always valid</p> <pre><code>(02)[\/.](0[1-9]|1[0-9]|2[0-8])[\/.](18|19|20)[0-9]{2} </code></pre> <p>February 29 also valid on leap years</p> <pre><code>(02)[\/.]29[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000) </code></pre> <p>which means it would be this if you put it all together:</p> <pre><code>((0[13578]|1[02])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](18|19|20)[0-9]{2})|((0[469]|11)[\/.](0[1-9]|[12][0-9]|30)[\/.](18|19|20)[0-9]{2})|((02)[\/.](0[1-9]|1[0-9]|2[0-8])[\/.](18|19|20)[0-9]{2})|((02)[\/.]29[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000)) </code></pre> <p>This version is a little shorter, but a little harder to understand.</p> <pre><code>((0[13578]|1[02])[\/.]31[\/.](18|19|20)[0-9]{2})|((01|0[3-9]|1[1-2])[\/.](29|30)[\/.](18|19|20)[0-9]{2})|((0[1-9]|1[0-2])[\/.](0[1-9]|1[0-9]|2[0-8])[\/.](18|19|20)[0-9]{2})|((02)[\/.]29[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000)) </code></pre> <p>These scripts are long and unmaintainable. It should be clear that this isn't a good idea, but it is possible.</p> <p>Caveats:</p> <ul> <li>range 1800-2099 (more can be added without too much difficulty, but requires changes in 4-6 disparate places)</li> <li>requires 2 digit months and days (the strictness could be removed from the expression in ~8 places)</li> <li><code>[\/.]</code> as seperators (8 places)</li> <li>Hasn't been tested (we could check it against all digit combinations and compare with the javascript date function? [proof that we're reinventing the wheel])</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload