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? Link to comment https://forums.phpfreaks.com/topic/133275-solved-regex-formatting-to-0-92-0-22-0-94-or-similar/ 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/133275-solved-regex-formatting-to-0-92-0-22-0-94-or-similar/#findComment-693163 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" ; ?> Link to comment https://forums.phpfreaks.com/topic/133275-solved-regex-formatting-to-0-92-0-22-0-94-or-similar/#findComment-693183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.