Jump to content

validating military time


Ninjakreborn

Recommended Posts

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.