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? Quote Link to comment 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"; } ?> Quote Link to comment 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"; } ?> Quote Link to comment 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}/'; Quote Link to comment 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! Quote Link to comment 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 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.