mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01: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
2 changed files with 7 additions and 1 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue