I’ve got this so far:
$post_dob = '19/08/1982';
$pattern = '/^\[0-9]{2}\/\[0-9]{2}\/\[0-9]{4}\$/';
if(!preg_match($pattern, $post_dob)){
$post_dob = explode('/', $_POST[$field]);
$post_dob = $post_dob[2] . '-' . $post_dob[1] . '-' . $post_dob[0];
return $post_dob;
}else{
return false;
}
It doesn’t seem to go wrong if i put 19/08/19823123
Any ideas what I’m doing wrong?
Try
But in reality, its much complicated than that. You’ll have to consider leap years and months having 30 days versus 31 days, etc.