I am trying to get a RegExp that accepts dates in the following formats:
dd/mm/yyyy dd/m/yyyy d/mm/yyyy d/m/yyyy
I am using this as my parseDate() /* which is supposed to return true if the date is in the right format */
function parseDate(&$date)
{
global $incorrectDateFormat;
// trim $date
$date = trim($date);
// if date is not in mm/yy/dddd format
if (!preg_match('/(0?[1-9]|1[012])[- \/.](0?[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/', $date))
{
// the format is invalid
echo $incorrectDateFormat;
return false;
}
return true;
}
The first argument in preg_match is the RegExp, and if I am not mistaken, ? after criteria means 0 or 1 occurrence of criteria. What is wrong with my RegExp? (It is returning true for these obviously incorrect dates: "102/25/2014 101/25/2014"