I was checking out cake's library and found a regular expression for date in its Validation.php file. I used it against various date values and found that it even matches wrong date values for some specific dates.
For example, It matches perfectly against following dates (which in fact, it should):-
20/01/2011
19/09/2017
20/01/1601
But when i use a wrong date value with 29 and/or 30 as a date, then surprisingly it matches them too (which it should not):-
30/,/1601
29/,/2017
https://regex101.com/r/8Q96bd/1/
One more interesting thing is, if you change date and use another date except 30 and 29, then expression wouldn't match it.
Use any other date except 29 & 30 and it doesn't match it:-
28/,/1600
https://regex101.com/r/UKuPWU/1/
Then why on the earth cakephp's date regex expression matches a wrong date value if it contains 30 & 29 as a date?
Here is the expression:-
^(?:(?:(?:31(\\\/|-|\\.|\\x20))(?:0?[13578]|1[02]))\1|(?:(?:29|30)([-\/])(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29([-\/])0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])([-\/])(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
You can find this expression inside cakephp lib directory (i am using cake 2.x though).
\lib\Cake\Utility\Validation.php (check out its date function)
My doubts are following:-
1. Why it is allowing comma in place of month only for 29 & 30?
2. Why it has used x20 in the regular expression? What is the need of using it in a DATE expression?
3. Is there any date standard/rule/specification am i missing which allows 29 & 30 to be used without mentioning month?
Could anyone please help in understanding the logic behind all these things?