代码:
/^[0-9]{4}(\-|\/)[0-9]{1,2}(\\1)[0-9]{1,2}(|\s+[0-9]{1,2}(:[0-9]{1,2}){0,2})$/
匹配:
0000-00-00
0000/00/00
0000-00-00 00
0000/00/00 00
0000-00-00 00:00
0000/00/00 00:00
0000-00-00 00:00:00
0000/00/00 00:00:00
用法:
<?php $time = '2011-12-29 12:21'; $reg = "/^[0-9]{4}(\-|\/)[0-9]{1,2}(\\1)[0-9]{1,2}(|\s+[0-9]{1,2}(:[0-9]{1,2}){0,2})$/"; if (preg_match($reg,$time)){ echo 1; }else{ echo 0; } ?>
<完>