blueman378 Posted November 19, 2008 Share Posted November 19, 2008 well basically what im trying to do is make sure a string is formatted like so 15-03-1991 so it must be numbers only two chars then a - then numbers only two chars then a - then numbers only 4 chars. any ideas? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted November 19, 2008 Share Posted November 19, 2008 <?php $str = "15-03-1991"; if (preg_match('/\d{2}-\d{2}-\d{4}/', $str)) { echo 'Good'; } else { echo 'Bad'; } ?> Quote Link to comment Share on other sites More sharing options...
ddrudik Posted November 19, 2008 Share Posted November 19, 2008 Probably should bound that with ^ and $ to test entire string: <?php $str = "15-03-1991"; echo preg_match('/^\d{2}-\d{2}-\d{4}$/', $str) ? "Good" : "Bad" ; ?> Quote Link to comment 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.