mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
fix integer validation process
This commit is contained in:
parent
971501551c
commit
7c990e39ef
@ -237,7 +237,7 @@ class Validator
|
||||
*/
|
||||
protected function validateInteger($field, $value)
|
||||
{
|
||||
return filter_var($value, \FILTER_VALIDATE_INT) !== false;
|
||||
return preg_match('/^-?([0-9])+$/i', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -110,6 +110,10 @@ class ValidateTest extends BaseTestCase
|
||||
$v = new Validator(array('num' => '41243'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertTrue($v->validate());
|
||||
|
||||
$v = new Validator(array('num' => '-41243'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testIntegerInvalid()
|
||||
@ -117,6 +121,22 @@ class ValidateTest extends BaseTestCase
|
||||
$v = new Validator(array('num' => '42.341569'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('num' => ' 41243'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('num' => '+1231'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('num' => '--1231'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('num' => '0x3a'));
|
||||
$v->rule('integer', 'num');
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testLengthValid()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user