Validating strings in YYYY-MM-DD format with Zend_Validate_Date in en_US locale

I am validating a user entered date string in the format YYYY-MM-DD

with Zend_Validate::is($value,'Date')

.

This call creates this hierarchy:

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

      

Finally, with this exception, it fails:

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 am using en_US as my application locale. How do I configure Zend_Validate to accept this date format? Is it possible to change the format of the date locale, for example?

+2


source to share


2 answers


Try the following:



$validator = new Zend_Validate_Date('YYYY-MM-DD');
if($validator->isValid($value))
    // yay

      

+9


source


zend_validate_date

has an error when you specify the following format yyyy-MM-dd

and if the date string 2011-10-11 12312

is passed in for validation it returns true instead of false !!



+5


source







All Articles