Using a perl regex

From: Date: Wed, 11 Feb 2004 17:09:22 +0000
Subject: Using a perl regex
Groups: php.general 
Request: Send a blank email to php-general+get-177421@lists.php.net to get a copy of this message
Hi, I am trying to use a perl regular expression to validate a form field where I am allowing someone to edit a sql date-time stamp in the format of '2004-02-05 21:43:34'. I have found a pattern that works (at http://www.regexplib.com/RETester.aspx?regexp_id=93) which is; 20\d{2}(-|\/)((0[1-9])|(1[0-2]))(-|\/)((0[1-9])|([1-2][0-9])|(3[0-1]))(T|\s) (([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9]) However, when I try to use it in a php if statement like this; if (!ereg("20\d{2}(-|\/)((0[1-9])|(1[0-2]))(-|\/)((0[1-9])|([1-2][0-9])|(3[0-1] ))(T|\s)(([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9])",$date_time)) { echo "<p>You must provide a date and time in the format YYYY-MM-DD HH:MM:SS</p>"; echo "<form><input type=\"button\" value=\"Go back\" onClick=\"history.back()\"></form>"; } It doesn't match and allow valid strings through. Any suggestions? TIA, Verdon Ps. Please cc me in any replies to list as I am in digest mode.

« previous php.general (#177421) next »