Zend_Validate_Date just doesn't work properly

It seems that it Zend_Validate_Datejust does not work properly. For instance:

$validator = new Zend_Validate_Date(array('format' => 'yyyy'));

This is a simple validator that should only take a four-digit year, but $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, it $otherValidator->isValid('15/13/10/12/1222')also returns true!

I am using Zend Framework 1.11.9. Is it just me or is it really a terrible validation class? (UPDATE: In other words, is something wrong with my code, or is it an error that needs to be sent?)

+5
source share
1 answer

As stated above, obviously there is a mistake with this class. Here is the workaround I came across 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
);

, - . , , .

+6

All Articles