fork(4) download
  1. <?php
  2.  
  3. function validaHoras($campo){
  4. return preg_match('/^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])/', $campo) ? $campo : false;
  5. }
  6.  
  7.  
  8. $arr = array('00:00', '19:59', '20:34', '24:33', '22:64', '07:59', '000:30', '30:50', '99:99');
  9.  
  10. foreach($arr as $item) var_dump(validaHoras($item));
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
string(5) "00:00"
string(5) "19:59"
string(5) "20:34"
bool(false)
bool(false)
string(5) "07:59"
bool(false)
bool(false)
bool(false)