centohi Posted November 17, 2007 Posted November 17, 2007 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? if (preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $dateStr) == TRUE) { echo "good"; } else { echo "bad"; } Quote
TCH-Bruce Posted November 17, 2007 Posted November 17, 2007 Welcome to the forums Craig I tested this: ><?php $dateStr = "2007-11-01"; if (preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $dateStr) == TRUE) { echo "good"; } else { echo "bad"; } ?> This returns good for me. Are you sure you are setting $dateStr to that date? It also works without the "== TRUE". Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.