DarkPrince2005 Posted July 11, 2011 Share Posted July 11, 2011 Can anyone assist in searching through a text field for dates? <?php $text = "01-01-2011"; if (preg_match("(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}", $text)) { return TRUE; echo 'true'; } else { return FALSE; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241674-preg_match/ Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 <?php $text = "01-01-2011"; if (preg_match("@[\d][\d]-[\d][\d]-[\d][\d][\d][\d]@", $text)) { echo 'true'; return TRUE; } else { echo "false"; return FALSE; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241674-preg_match/#findComment-1241243 Share on other sites More sharing options...
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.