View Single Post
  #1   (View Single Post)  
Old 16th August 2008
cajunman4life cajunman4life is offline
Real Name: Aaron Graves
Package Pilot
 
Join Date: May 2008
Location: Coolidge, Arizona
Posts: 203
Default PHP regular expression help

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?
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident!
Reply With Quote