2016-07-21 15:09:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2016-07-21 15:09:38 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-21 15:09:38 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-08-07 19:38:11 +02:00
|
|
|
use function is_nan;
|
|
|
|
use function is_numeric;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates if the input is a number.
|
|
|
|
*
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
* @author Ismael Elias <ismael.esq@hotmail.com>
|
|
|
|
* @author Vitaliy <reboot.m@gmail.com>
|
|
|
|
*/
|
|
|
|
final class Number extends AbstractRule
|
2016-07-21 15:09:38 +02:00
|
|
|
{
|
2018-08-07 19:38:11 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-08-07 19:38:11 +02:00
|
|
|
*/
|
2018-01-28 15:41:31 +01:00
|
|
|
public function validate($input): bool
|
2016-07-21 15:09:38 +02:00
|
|
|
{
|
|
|
|
if (!is_numeric($input)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
return !is_nan((float) $input);
|
2016-07-21 15:09:38 +02:00
|
|
|
}
|
|
|
|
}
|