1 | <?php |
||
23 | class NumberValidator extends Validator |
||
24 | { |
||
25 | /** |
||
26 | * @var bool whether the attribute value can only be an integer. Defaults to false. |
||
27 | */ |
||
28 | public $integerOnly = false; |
||
29 | /** |
||
30 | * @var int|float upper limit of the number. Defaults to null, meaning no upper limit. |
||
31 | * @see tooBig for the customized message used when the number is too big. |
||
32 | */ |
||
33 | public $max; |
||
34 | /** |
||
35 | * @var int|float lower limit of the number. Defaults to null, meaning no lower limit. |
||
36 | * @see tooSmall for the customized message used when the number is too small. |
||
37 | */ |
||
38 | public $min; |
||
39 | /** |
||
40 | * @var string user-defined error message used when the value is bigger than [[max]]. |
||
41 | */ |
||
42 | public $tooBig; |
||
43 | /** |
||
44 | * @var string user-defined error message used when the value is smaller than [[min]]. |
||
45 | */ |
||
46 | public $tooSmall; |
||
47 | /** |
||
48 | * @var string the regular expression for matching integers. |
||
49 | */ |
||
50 | public $integerPattern = '/^\s*[+-]?\d+\s*$/'; |
||
51 | /** |
||
52 | * @var string the regular expression for matching numbers. It defaults to a pattern |
||
53 | * that matches floating numbers with optional exponential part (e.g. -1.23e-10). |
||
54 | */ |
||
55 | public $numberPattern = '/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/'; |
||
56 | |||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 53 | public function init() |
|
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 19 | public function validateAttribute($model, $attribute) |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 11 | protected function validateValue($value) |
|
118 | |||
119 | /* |
||
120 | * @param mixed $value the data value to be checked. |
||
121 | */ |
||
122 | 27 | private function isNotNumber($value) |
|
128 | } |
||
129 |