Im trying to to set up a php date validation (MM/DD/YYYY) but I'm having issues. Here is a sample of what I got:
$date_regex = '%\A(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d\z%';
$test_date = '03/22/2010';
if (preg_match($date_regex, $test_date,$_POST['birthday']) ==true) {
$errors[] = 'user name most have no spaces';`
I know this is an older post, but I've developed the following function for validating a date:
We can use simple "date" input type, like below:
Then we can link DateTime interface with built-in function 'explode':
I tested it on Google Chrome and IE, everything works correctly. Furthemore, Chrome display simple additional interface. If you don't write anything in input or write it in bad format (correctly is following: '1919-12-23'), you will get the first statement. If you write everything in good format, but you type wrong date (I assumed that nobody could born before XX century), your controller will send the second statement.
Not sure if this answer the question or going to help....
Instead of the bulky DateTime object .. just use the core date() function
I think it will help somebody.
You could use checkdate. For example, something like this:
A more paranoid approach, that doesn't blindly believe the input: