Sasa Posted September 29, 2010 Report Share Posted September 29, 2010 man datums un laik vajadzīgs formā yyyyMMddHHmmss kā lai ievadīto stringu pārbauda vai tas atbilst datumam un laikam šobrīd mana regulārā izteiksme, kas savākta no diviem atsevišķiem diez ko labi nestrādā pārbaudot laika daļu: (19|20)\d\d()(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])(([0-1]?[0-9])|([2][0-3]))([0-5]?[0-9])(([0-5]?[0-9])) testēju uz apmēram kaut kā ša: 20100928100000 Quote Link to comment Share on other sites More sharing options...
marcis Posted September 29, 2010 Report Share Posted September 29, 2010 function check_date($datestr){ $m = array(); if(!preg_match('/^(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2})(?P<hour>\d{2})(?P<minute>\d{2})(?P<second>\d{2})$/', $datestr, $m)) return false; if(($t = mktime((int)$m['hour'], (int)$m['minute'], (int)$m['second'], (int)$m['month'], (int)$m['day'], (int)$m['year'])) === false) return false; return $datestr == date('YmdHis', $t); } var_dump(check_date('20100928100000'), check_date('1234'), check_date('20131928105699')); 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.