The syntax of the preg_match function is that:
preg_match (string pattern, string string [, array pattern_array],[, int $flags [, int $offset]]]);
In the above function first and second parameter are mandatory and the rest of the parameters are optional.
So, we only use the mandatory parameter to validate the date.
For example we have a given date and use preg_match function to validate it:
$date="2015-07-21";
if (preg_match('/^((19|20)\\d\\d)[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/',$date))
{
return true;
}else{
return false;
}
In above scenario preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.
0 Comment(s)