views:

974

answers:

1

I'm validating user entered date string in YYYY-MM-DD format using Zend_Validate::is($value,'Date').

this call causes this hierarchy:

Zend_Validate::is()
Zend_Validate_Date->isValid()
Zend_Date::isDate()
Zend_Locale_Format::getDate()
Zend_Locale_Format::_parseDate()

and then fials with this exception:

Zend_Locale_Exception: Unable to parse date '2009-09-08' using 'MMM d, y' (M <> y) in /usr/share/php/Zend/Locale/Format.php on line 1001

I'm using en_US as application locale. how can I configure Zend_Validate accepts my '2009-09-08' format? Is it possible to change the locale format of date?

+1  A: 

Try that:

$validator = new Zend_Validate_Date('YYYY-MM-DD');
if($validator->isValid($value))
    // yay
janoliver
thanks a lot. I've never used individual Zend_Validate_X classes before. this is more customizable.
farzad
You should use `'yyyy-MM-dd'` though... YYYY is "ISO Year" (which is subtly different near the beggining of the year) and "DD" day of year not day of month. http://framework.zend.com/manual/en/zend.date.constants.html#zend.date.constants.selfdefinedformats.table
gnarf