Hey guys, writing a regex for PHP to validate date input to be put in an entry in MySQL.
Format must be YYYY-MM-DD HH:MM:SS
I have this:
Code:
$must_match = "^[0-9]{4}\-[0-9]{2}\-[0-9]{2}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}$";
if(preg_match($must_match, $dte) && $dte) {
if(!$dte) {
$query = "INSERT INTO $table VALUES ('', NOW(), 'ajgraves', '$post');";
} else {
$query = "INSERT INTO $table VALUES ('', '$dte', 'ajgraves', '$post');";
}
} else {
die("ERROR: You entered an invalid date");
}
mysql_query($query);
And no matter what I enter, it always fails. Any ideas?