PHP验证字符串和日期[重复]

This question already has an answer here:

In PHP, I have a string that I need to check if it is the following format: XXXX-YY-ZZ

Where x,y and z are integers. So the string contains 3 integers separated by 2 dashes with the following rules:

xxxx > 2003 
yy >= 0 and yy <= 12 
zz >= 1 zz <= 31

What would be the easiest way to validate this?

</div>
function validateDate($date)
{
    $d = DateTime::createFromFormat('Y-m-d', $date);
    return $d && $d->format('Y-m-d') == $date;
}

function was copied from this answer or php.net