Date regex for form validation

Here’s the format I’m trying to match:

Sat, 08-21-2010

Here’s the regex:

preg_match('/^\\w{3},\\s(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$/',$datepicker)

But no joy. What have I missed?

If you want, you could use the © symbol for delimiters. So far, I’ve found using that hasn’t interfered with anything else.

Yes, I’ve echoed it & the output is correct. I was able to get it working by replacing the ‘/’ delimiters with ‘%’:

preg_match('%^\\w{3},\\s(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$%',$datepicker)

which made the error clear: I didn’t escape the forward slashes in the list of separators.

BTW, the alternate separators are in case the user fills in the field manually (i’m using the jQuery datepicker plugin, but it’s still possible to enter text in the field, + I want the form to degrade gracefully).

Thanks for the help,

–cz

The regular expression itself works.

I just tweaked it a bit by removing the excess separation characters between the day/month/year:

^\\w{3},\\s(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\\d\\d$

Can you do an echo on the $datepicker variable?