Page 1 of 1

Checking for valid dates - SOLVED

Posted: Tue Jul 24, 2007 6:13 pm
by ReverendDexter
Does anyone know of a way to check if a date is valid?

I'm currently using a regex string to check, but it lets a lot of invalid dates through, like 2007-01-39, or 2019-02-30. I'm currently only allowing for dates of the format yyyy-mm-dd, though I'm not opposed to opening that up.

Here's my current regex string:

Code: Select all

/2[0-9]{3}-(0[1-9]|[11,12])-[0-3][0-9]/
Is there a class or function I could be using?

Posted: Tue Jul 24, 2007 6:20 pm
by John Cartwright
checkdate() might be of interest

Posted: Tue Jul 24, 2007 6:38 pm
by ReverendDexter
And very interesting it was.

Thank you, that did exactly what I needed.