mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Fix #33 Validation for length - Message is incorrect for between cases
This commit is contained in:
parent
97ae575141
commit
db6d49baf6
@ -139,6 +139,21 @@ class Validator
|
||||
return $this->validateRequired($field, $value) && in_array($value, $acceptable, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the length of a string
|
||||
*
|
||||
* @param string $filed
|
||||
* @param mixed $value
|
||||
* @param array $params
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function validateLengthBetween($filed, $value, $params)
|
||||
{
|
||||
$length = $this->stringLength($value);
|
||||
return $length >= $params[0] && $length <= $params[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a field is numeric
|
||||
*
|
||||
|
||||
@ -136,14 +136,14 @@ class ValidateTest extends BaseTestCase
|
||||
public function testLengthBetweenValid()
|
||||
{
|
||||
$v = new Validator(array('str' => 'happy'));
|
||||
$v->rule('length', 'str', 2, 8);
|
||||
$v->rule('lengthBetween', 'str', 2, 8);
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testLengthBetweenInvalid()
|
||||
{
|
||||
$v = new Validator(array('str' => 'sad'));
|
||||
$v->rule('length', 'str', 4, 10);
|
||||
$v->rule('lengthBetween', 'str', 4, 10);
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user