2

I have the following code:

<?php

  $dateString = '12.12.12';
  $dateCheckArray['format'] = 'dd-mm-yyyy';
  $validator = new Zend_Validate_Date($dateCheckArray);
  if ($validator->isValid($dateString)) {
      echo 'valid';
  }
  else {
      echo 'invalid';
  }

The code works ok for most formats, but for the one specified it fails when using a . date instead of a - date.

For example for the date specified before (12.12.12) the script will echo 'valid', even though it obviously doesn't fit the format.

Can anyone point out why this is happening?

Note: This is zend 1.

zozo
  • 8,230
  • 19
  • 79
  • 134

1 Answers1

1

There is a bug in ZF-7583: Zend_Date::isDate accepts invalid dates. Thats why some dates are showing in correct. Its better to use a regex validation for it.

You can check this post for the regex Regex to validate date format dd/mm/yyyy

Community
  • 1
  • 1
Nandakumar V
  • 4,317
  • 4
  • 27
  • 47
  • Only about 6 years since some1 pointed out that bug :)). Nice... feeling trust in Zend going down. – zozo May 27 '15 at 06:52
  • @zozo It seems they have solved the issue [Where do I find Date class in Zend Framework 2.0?](http://stackoverflow.com/questions/12401221/where-do-i-find-date-class-in-zend-framework-2-0) – Nandakumar V May 27 '15 at 07:00
  • It is fixed in 2.0, but can't exactly port the whole project over night :). 1.x and 2.0 are not exactly compatible. Anyway... solved. Ty 4 helping. – zozo May 27 '15 at 07:51
  • actually its not fixed :). Please check the link. – Nandakumar V May 27 '15 at 07:51
  • Hm... worked fine on my test yesterday. Maybe got in a particular case. – zozo May 27 '15 at 07:55