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