@@ 14-44 (lines=31) @@ | ||
11 | /** |
|
12 | * Validate e-mail address. |
|
13 | */ |
|
14 | class CheckEmail implements ValidatorInterface |
|
15 | { |
|
16 | /** |
|
17 | * @var string|null |
|
18 | */ |
|
19 | private $error; |
|
20 | ||
21 | /** |
|
22 | * @param string|null $error optional custom error message |
|
23 | */ |
|
24 | public function __construct($error = null) |
|
25 | { |
|
26 | $this->error = $error; |
|
27 | } |
|
28 | ||
29 | public function validate(FieldInterface $field, InputModel $model, InputValidation $validation) |
|
30 | { |
|
31 | $input = $model->getInput($field); |
|
32 | ||
33 | if ($input === null) { |
|
34 | return; // no input |
|
35 | } |
|
36 | ||
37 | if (filter_var($input, FILTER_VALIDATE_EMAIL) === false) { |
|
38 | $model->setError( |
|
39 | $field, |
|
40 | $this->error ?: lang::text("mindplay/kissform", "email", ["field" => $validation->getLabel($field)]) |
|
41 | ); |
|
42 | } |
|
43 | } |
|
44 | } |
|
45 |
@@ 14-44 (lines=31) @@ | ||
11 | /** |
|
12 | * Validate numeric input, allowing floating point values. |
|
13 | */ |
|
14 | class CheckFloat implements ValidatorInterface |
|
15 | { |
|
16 | /** |
|
17 | * @var string|null |
|
18 | */ |
|
19 | protected $error; |
|
20 | ||
21 | /** |
|
22 | * @param string|null $error optional custom error message |
|
23 | */ |
|
24 | public function __construct($error = null) |
|
25 | { |
|
26 | $this->error = $error; |
|
27 | } |
|
28 | ||
29 | public function validate(FieldInterface $field, InputModel $model, InputValidation $validation) |
|
30 | { |
|
31 | $input = $model->getInput($field); |
|
32 | ||
33 | if ($input === null) { |
|
34 | return; // no input |
|
35 | } |
|
36 | ||
37 | if (filter_var($input, FILTER_VALIDATE_FLOAT) === false) { |
|
38 | $model->setError( |
|
39 | $field, |
|
40 | $this->error ?: lang::text("mindplay/kissform", "float", ["field" => $validation->getLabel($field)]) |
|
41 | ); |
|
42 | } |
|
43 | } |
|
44 | } |
|
45 |
@@ 14-41 (lines=28) @@ | ||
11 | /** |
|
12 | * Validate whole number input. |
|
13 | */ |
|
14 | class CheckInt implements ValidatorInterface |
|
15 | { |
|
16 | /** |
|
17 | * @var string|null |
|
18 | */ |
|
19 | private $error; |
|
20 | ||
21 | /** |
|
22 | * @param string|null $error optional custom error message |
|
23 | */ |
|
24 | public function __construct($error = null) |
|
25 | { |
|
26 | $this->error = $error; |
|
27 | } |
|
28 | ||
29 | public function validate(FieldInterface $field, InputModel $model, InputValidation $validation) |
|
30 | { |
|
31 | $input = $model->getInput($field); |
|
32 | ||
33 | if ($input === null) { |
|
34 | return; // no input |
|
35 | } |
|
36 | ||
37 | if (filter_var($input, FILTER_VALIDATE_INT) === false) { |
|
38 | $model->setError($field, $this->error ?: lang::text("mindplay/kissform", "int", ["field" => $validation->getLabel($field)])); |
|
39 | } |
|
40 | } |
|
41 | } |
|
42 |