Fix Validation::time so it accepts spaces.

Fixes #2015
This commit is contained in:
mark_story 2011-09-22 20:53:56 -04:00
parent 07f6803540
commit 6a05cad69f
2 changed files with 3 additions and 1 deletions

View file

@ -429,7 +429,7 @@ class Validation extends Object {
$_this =& Validation::getInstance();
$_this->__reset();
$_this->check = $check;
$_this->regex = '%^((0?[1-9]|1[012])(:[0-5]\d){0,2}([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%';
$_this->regex = '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%';
return $_this->_check();
}

View file

@ -1509,6 +1509,8 @@ class ValidationTest extends CakeTestCase {
$this->assertTrue(Validation::time('12:01am'));
$this->assertTrue(Validation::time('12:01pm'));
$this->assertTrue(Validation::time('1pm'));
$this->assertTrue(Validation::time('1 pm'));
$this->assertTrue(Validation::time('1 PM'));
$this->assertTrue(Validation::time('01:00'));
$this->assertFalse(Validation::time('1:00'));
$this->assertTrue(Validation::time('1:00pm'));