views:

550

answers:

1

By default a Zend Framework date validator uses the date format yyyy-MM-dd:

$dateValidator = new Zend_Validate_Date();

But I want to add hour and minute validation. In other words, I want to require the user to enter the hour and minute. But the following does not work:

$dateValidator = new Zend_Validate_Date('yyyy-MM-dd hh:ii');

If I enter 2010-02-01, I get an error saying that the date doesn't fit the format. If I enter 2010-02-01 3, it doesn't complain. What's it's doing is assuming that the user means 2010-02-01 03:00 rather than enforcing that the user enters the date in the given format.

How can I enforce that the date must be entered in the given format?

+1  A: 

Please see: http://framework.zend.com/issues/browse/ZF-6369

Basically what it comes down to is that the code underlying the format validation doesn't work correctly. Rather than using strict validation, it will try to coerce the provided date into something that will validate and so you get hanky results.

It does look like the bug has been marked as 'Major' so hopefully we'll see a fix soon.

Noah Goodrich