Dooling Posted July 6, 2006 Report Share Posted July 6, 2006 Lieta tāda -> Man vajag pārbaudīt ievadīt vienu lauku. Drīkst ievadīt tikai pēc šāda šablona hh:mm:ss, Piemēram 00:59:15 Kā lai to paveic? Ar funkcijas preg_match palīdzību? Vai arī ieteiksiet kaut ko citu paņēmienu? Link to comment Share on other sites More sharing options...
v3rb0 Posted July 6, 2006 Report Share Posted July 6, 2006 (edited) ar explode, count un bik ifiem. $chunks = @explode(':', $lauks); if(count($chunks) != 3 || strlen($chunks[0]) != 2 || strlen($chunks[1]) != 2 || strlen($chunks[2]) != 2 )) die('ne to ievadiji, tagad tu mirsi!'); if($chunks[0] > 23) die('ūja, stundas pa daudz'); if($chunks[1] > 59) die('uuja minutes pa daudz'); if($chunks[2] > 59) die('ūja, sekundes pa daudz'); echo 'ir ok'; Edited July 6, 2006 by v3rb0 Link to comment Share on other sites More sharing options...
Dooling Posted July 6, 2006 Author Report Share Posted July 6, 2006 Paldies! ;) Link to comment Share on other sites More sharing options...
Delfins Posted July 6, 2006 Report Share Posted July 6, 2006 (edited) Es gan ļautu ievadīt arī [hh], gan [hh]:[mm] $chunk[0] = abs((int) $chunk[0]); $chunk[1] = abs((int) $chunk[1]); $chunk[2] = abs((int) $chunk[2]); $ret = ($chunk[0]<24); $ret = $ret & (!empty($chunk[1]) && $chunk[1]<60); $ret = $ret & (!empty($chunk[2]) && $chunk[2]<60); $newTime = sprintf("%02d:%02d:%02d",$chunk[0],$chunk[1],$chunk[2]); Edited July 6, 2006 by Delfins Link to comment Share on other sites More sharing options...
KAC Posted July 6, 2006 Report Share Posted July 6, 2006 es gan splitoju un paarbaudu ar checkdate Link to comment Share on other sites More sharing options...
Dooling Posted July 6, 2006 Author Report Share Posted July 6, 2006 es gan splitoju un paarbaudu ar checkdate Ar checkdate funckiju var pārbaudīt gadu, mēnesi un dienu nevis stundas, minūtes un sekundes ;) Link to comment Share on other sites More sharing options...
Recommended Posts