Changeset 7589
- Timestamp:
- 02/23/08 19:30:55 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/lib/validator/sfNumberValidator.class.php
r3233 r7589 46 46 public function execute(&$value, &$error) 47 47 { 48 if (! is_numeric($value))48 if (!preg_match('/^\d+(\.\d+)?$/', $value)) 49 49 { 50 50 // it's NaN, what nerve! branches/1.0/test/unit/validator/sfNumberValidatorTest.php
r2276 r7589 13 13 require_once($_test_dir.'/unit/sfValidatorTestHelper.class.php'); 14 14 15 $t = new lime_test( 49, new lime_output_color());15 $t = new lime_test(51, new lime_output_color()); 16 16 17 17 $context = new sfContext(); … … 25 25 $t->ok($v->execute($number, $error), '->execute() returns true if you don\'t define any parameter'); 26 26 27 $number = 'not a number'; 28 $error = null; 29 $t->ok(!$v->execute($number, $error), '->execute() returns "nan_error" if value is not a number'); 30 $t->is($error, 'Input is not a number', '->execute() changes "$error" with a default message if it returns false'); 27 foreach (array('not a number', '0xFE') as $number) 28 { 29 $error = null; 30 $t->ok(!$v->execute($number, $error), '->execute() returns "nan_error" if value is not a number'); 31 $t->is($error, 'Input is not a number', '->execute() changes "$error" with a default message if it returns false'); 32 } 31 33 32 34 foreach (array('any', 'decimal', 'float', 'int', 'integer') as $type)