1 | <?php |
||
20 | class StringValidator extends Validator |
||
21 | { |
||
22 | /** |
||
23 | * @var int|array specifies the length limit of the value to be validated. |
||
24 | * This can be specified in one of the following forms: |
||
25 | * |
||
26 | * - an integer: the exact length that the value should be of; |
||
27 | * - an array of one element: the minimum length that the value should be of. For example, `[8]`. |
||
28 | * This will overwrite [[min]]. |
||
29 | * - an array of two elements: the minimum and maximum lengths that the value should be of. |
||
30 | * For example, `[8, 128]`. This will overwrite both [[min]] and [[max]]. |
||
31 | * @see tooShort for the customized message for a too short string. |
||
32 | * @see tooLong for the customized message for a too long string. |
||
33 | * @see notEqual for the customized message for a string that does not match desired length. |
||
34 | */ |
||
35 | public $length; |
||
36 | /** |
||
37 | * @var int maximum length. If not set, it means no maximum length limit. |
||
38 | * @see tooLong for the customized message for a too long string. |
||
39 | */ |
||
40 | public $max; |
||
41 | /** |
||
42 | * @var int minimum length. If not set, it means no minimum length limit. |
||
43 | * @see tooShort for the customized message for a too short string. |
||
44 | */ |
||
45 | public $min; |
||
46 | /** |
||
47 | * @var string user-defined error message used when the value is not a string. |
||
48 | */ |
||
49 | public $message; |
||
50 | /** |
||
51 | * @var string user-defined error message used when the length of the value is smaller than [[min]]. |
||
52 | */ |
||
53 | public $tooShort; |
||
54 | /** |
||
55 | * @var string user-defined error message used when the length of the value is greater than [[max]]. |
||
56 | */ |
||
57 | public $tooLong; |
||
58 | /** |
||
59 | * @var string user-defined error message used when the length of the value is not equal to [[length]]. |
||
60 | */ |
||
61 | public $notEqual; |
||
62 | /** |
||
63 | * @var string the encoding of the string value to be validated (e.g. 'UTF-8'). |
||
64 | * If this property is not set, [[\yii\base\Application::charset]] will be used. |
||
65 | */ |
||
66 | public $encoding; |
||
67 | |||
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | 21 | public function init() |
|
100 | |||
101 | /** |
||
102 | * @inheritdoc |
||
103 | */ |
||
104 | 7 | public function validateAttribute($model, $attribute) |
|
126 | |||
127 | /** |
||
128 | * @inheritdoc |
||
129 | */ |
||
130 | 3 | protected function validateValue($value) |
|
150 | |||
151 | /** |
||
152 | * @inheritdoc |
||
153 | */ |
||
154 | public function clientValidateAttribute($model, $attribute, $view) |
||
161 | |||
162 | public function getClientOptions($model, $attribute) |
||
199 | } |
||
200 |