Jump to content

[SOLVED] Date Regex


bigdspbandj

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.