I'm no master at regular expressions but can someone tell me whats wrong with it that it thinks 13-22-2005 is valid? Trying to validate the date to mysql date type.
if (!ereg("([1-9]|0[1-9]|1[0-2])(/|-)(0[1-9]|[1-2][0-9]|3[0-1])(/|-)[1-9][0-9]{3}$", $field_list[$i]))
It skipped the 1 and matched the 3 against 1-9. Put a beginning anchor () at the start of your regex.
Ah ok thanks a lot...but 1 more thing...now I tried to validate
1-1-2005 and it comes out invalid 🙁
Your regex requires that the day is two digit (leading 0).
Would separating $field_list[$i] into separate parts for month, day, and year, and then using [man]checkdate[/man] be more reliable? For one thing, you then won't need an additional test to check for 2-29-2005.
Hm ok...I didn't even know of the checkdate function. Works well because the fields are acctually seperated from the start. Thanks man.