It appears that Zend_Validate_Date
just simply doesn't work properly. For example:
$validator = new Zend_Validate_Date(array('format' => 'yyyy'));
This is a simple validator that should only accept a four digit year, yet $validator->isValid('1/2/3')
returns true! Really, Zend?
Or how about this:
$otherValidator = new Zend_Validate_Date(array('format' => 'mm/dd/yyyy'));
Even with the above code, $otherValidator->isValid('15/13/10/12/1222')
returns true
too!
I'm using Zend Framework 1.11.9. Is it just me or is this a really terrible validation class? (UPDATE: In other words, is there something wrong with my code, or is this a bug that should be submitted?)
As the comments above say, apparently there's a bug with this class. Here is the workaround I came up with, using Zend_Validate_Regex
:
$validator = new Zend_Validate_Regex(
array('pattern' => '/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/')
);
$validator->setMessage(
"Date does not match the format 'mm/dd/yyyy'",
Zend_Validate_Regex::NOT_MATCH
);
Hopefully that will help someone else. Please note that I only want slashes as separator, not dots or dashes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With