Jump to content

Recommended Posts

Posted

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";

}

Posted

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".

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...