When $dateStr is assigned the value "2007-11-01" (as an example), does anyone have any ideas why this code always echoes "bad". What am I doing wrong?<br /><br /><br />if (preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $dateStr) == TRUE)<br />{<br /> echo "good";<br />}<br />else<br />{<br /> echo "bad";<br />} <br /><!--content-->
Welcome to the forums Craig <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><br /><br />I tested this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />$dateStr = "2007-11-01";<br />if (preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $dateStr) == TRUE)<br />{<br />echo "good";<br />}<br />else<br />{<br />echo "bad";<br />} <br /><br />?><!--c2--></div><!--ec2--><br /><br />This returns good for me. Are you sure you are setting $dateStr to that date? It also works without the "== TRUE".<!--content-->
Welcome to the forum, Craig. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums Craig <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><br /><br />I tested this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />$dateStr = "2007-11-01";<br />if (preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $dateStr) == TRUE)<br />{<br />echo "good";<br />}<br />else<br />{<br />echo "bad";<br />} <br /><br />?><!--c2--></div><!--ec2--><br /><br />This returns good for me. Are you sure you are setting $dateStr to that date? It also works without the "== TRUE".<!--content-->
Welcome to the forum, Craig. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->