mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
Do not consider any float as integer
Values like "500.00" or 1.0 should not be considered as integer values even though there is no data loss when they're converted to integer. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
0e73bc732e
commit
54d17abcee
|
@ -15,6 +15,10 @@ class IntVal extends AbstractRule
|
|||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return is_numeric($input) && (int) $input == $input;
|
||||
if (is_float($input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false !== filter_var($input, FILTER_VALIDATE_INT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ class IntValTest extends \PHPUnit_Framework_TestCase
|
|||
[''],
|
||||
[null],
|
||||
['a'],
|
||||
['1.0'],
|
||||
[1.0],
|
||||
[' '],
|
||||
['Foo'],
|
||||
['1.44'],
|
||||
|
|
Loading…
Reference in a new issue