Ninjakreborn Posted November 14, 2006 Share Posted November 14, 2006 How do you properly validate military time using regular expressions. RIght now I am just making the maxlength 4 and using is_numeric but I don't think that will do total validation as someone could get around that, any advice? Link to comment https://forums.phpfreaks.com/topic/27216-validating-military-time/ Share on other sites More sharing options...
effigy Posted November 14, 2006 Share Posted November 14, 2006 Try this:[code]<pre><?php $hours = range(0, 24); $mins = range(0, 60); foreach ($hours as $hour) { foreach ($mins as $min) { $time = sprintf('%02d:%02d', $hour, $min); echo $time, ' => ', (preg_match('/^24:00$|^(?:[01][0-9]|2[0-3]):(?:[0-5][0-9])$/', $time) ? 'OK' : 'Not OK'), '<br>'; } }?></pre>[/code] Link to comment https://forums.phpfreaks.com/topic/27216-validating-military-time/#findComment-124444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.