forked from particle-php/Validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumeric.php
47 lines (43 loc) · 1.15 KB
/
Numeric.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Particle.
*
* @link http://github.com/particle-php for the canonical source repository
* @copyright Copyright (c) 2005-2016 Particle (http://particle-php.com)
* @license https://github.com/particle-php/validator/blob/master/LICENSE New BSD License
*/
namespace Particle\Validator\Rule;
use Particle\Validator\Rule;
/**
* This rule is for validating if a value represents an numeric value (float, int).
*
* @package Particle\Validator\Rule
*/
class Numeric extends Rule
{
/**
* A constant that will be used when the value does not represent a numeric value.
*/
const NOT_NUMERIC = 'Numeric::NOT_NUMERIC';
/**
* The message templates which can be returned by this validator.
*
* @var array
*/
protected $messageTemplates = [
self::NOT_NUMERIC => '{{ name }} must be numeric',
];
/**
* Validates if $value represents an integer or a float value.
*
* @param mixed $value
* @return bool
*/
public function validate($value)
{
if (is_numeric($value)) {
return true;
}
return $this->error(self::NOT_NUMERIC);
}
}