bigdspbandj Posted October 19, 2007 Share Posted October 19, 2007 When I use this date regex: '(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}' I get this error: Warning: preg_match() [function.preg-match]: Unknown modifier '[' in /Users/bigdspbandj/Sites/optimal_web/customer_tracking/submit_job_mgmt_trust.php on line 13 I am trying to match a date string that doesn't match mm/(or -)dd/(or -)yyyy. Anyone have one handy? Link to comment https://forums.phpfreaks.com/topic/74002-solved-date-regex/ Share on other sites More sharing options...
MadTechie Posted October 19, 2007 Share Posted October 19, 2007 <?php if (preg_match('%\A(?:^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}$)\Z%', $date)) { echo "valid date"; } else { echo "Invalid date"; } ?> Link to comment https://forums.phpfreaks.com/topic/74002-solved-date-regex/#findComment-373535 Share on other sites More sharing options...
MadTechie Posted October 19, 2007 Share Posted October 19, 2007 Oppps thats UK this is US <?php if (preg_match('%\A(?:^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}$)\Z%', $date)) { echo "valid date"; } else { echo "Invalid date"; } ?> Link to comment https://forums.phpfreaks.com/topic/74002-solved-date-regex/#findComment-373538 Share on other sites More sharing options...
BlueSkyIS Posted October 19, 2007 Share Posted October 19, 2007 fyi, the failure of the original regex was due to an incorrect pattern. a fixed version might be $pattern = '/(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)[0-9]{2}/'; Link to comment https://forums.phpfreaks.com/topic/74002-solved-date-regex/#findComment-373539 Share on other sites More sharing options...
bigdspbandj Posted October 19, 2007 Author Share Posted October 19, 2007 Cool deal. Thank you very much guys! Link to comment https://forums.phpfreaks.com/topic/74002-solved-date-regex/#findComment-373540 Share on other sites More sharing options...
MadTechie Posted October 19, 2007 Share Posted October 19, 2007 this may work better.. ie no 31 days in Feb <?php $date = "10/19/2007"; $result = "InValid"; if (preg_match('%(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}%', $date, $regs)) { if (checkdate($regs[1], $regs[2], $regs[3])) { $result = "Valid"; } } echo $result; ?> **UNTESTED Link to comment https://forums.phpfreaks.com/topic/74002-solved-date-regex/#findComment-373541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.