user1060187
user1060187

Reputation: 977

php reg expression to check date format is correct

I'm currently trying to find out if a date is in the format of YYYY-DD-MM.

In PHP, I've got this:

if (preg_match('(\d{4})(-)(\d{2})(-)(\d{2})$', $newDateOfBirth))

However I keep getting the following error:

Warning: preg_match(): Unknown modifier '(' in C:\webserver\webroot\index.php on line 105

Upvotes: 0

Views: 651

Answers (1)

SomeoneYouDontKnow
SomeoneYouDontKnow

Reputation: 1299

You are missing the delimiters:

if (preg_match('~(\d{4})(-)(\d{2})(-)(\d{2})$~', $newDateOfBirth))

Upvotes: 1

Related Questions