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? Quote Link to comment 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] 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.