Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

EmailAddressValidator.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Validator;
8
9 use eZ\Publish\Core\FieldType\Validator;
10 use eZ\Publish\Core\FieldType\ValidationError;
11 use eZ\Publish\Core\FieldType\Value as BaseValue;
12
19 class EmailAddressValidator extends Validator
20 {
21 protected $constraints = [
22 'Extent' => false,
23 ];
24
25 protected $constraintsSchema = [
26 'Extent' => [
27 'type' => 'string',
28 'default' => 'regex',
29 ],
30 ];
31
39 public function validateConstraints($constraints)
40 {
41 $validationErrors = [];
42 foreach ($constraints as $name => $value) {
43 switch ($name) {
44 case 'Extent':
45
46 if ($value !== false && $value !== 'regex') {
47 $validationErrors[] = new ValidationError(
48 "Validator parameter '%parameter%' value must be regex for now",
49 null,
50 [
51 '%parameter%' => $name,
52 ],
53 "[EmailAddressValidator][$name]"
54 );
55 }
56 break;
57 default:
58 $validationErrors[] = new ValidationError(
59 "Validator parameter '%parameter%' is unknown",
60 null,
61 [
62 '%parameter%' => $name,
63 ],
64 "[EmailAddressValidator][$name]"
65 );
66 }
67 }
68
69 return $validationErrors;
70 }
71
87 public function validate(BaseValue $value)
88 {
89 $pattern = '/^((\"[^\"\f\n\r\t\v\b]+\")|([A-Za-z0-9_\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[A-Za-z0-9_\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]{2,}))$/';
90
91 if (preg_match($pattern, $value->email)) {
92 return true;
93 }
94
95 $this->errors[] = new ValidationError(
96 'The value must be a valid email address.',
97 null,
98 [],
99 'email'
100 );
101
102 return false;
103 }
104 }
eZ\Publish\Core\FieldType\ValidationError
Class for validation errors.
Definition: Core/FieldType/ValidationError.php:17
eZ\Publish\Core\FieldType\Validator\EmailAddressValidator
Definition: EmailAddressValidator.php:20
eZ\Publish\Core\FieldType\Validator\EmailAddressValidator\validate
validate(BaseValue $value)
Perform validation on $value.
Definition: EmailAddressValidator.php:87
eZ\Publish\Core\FieldType\Validator\EmailAddressValidator\validateConstraints
validateConstraints($constraints)
@abstract
Definition: EmailAddressValidator.php:39
eZ\Publish\Core\FieldType\Validator\EmailAddressValidator\$constraints
$constraints
Definition: EmailAddressValidator.php:21
eZ\Publish\Core\FieldType\Validator\EmailAddressValidator\$constraintsSchema
$constraintsSchema
Definition: EmailAddressValidator.php:25
eZ\Publish\Core\FieldType\Validator
Base field type validator validator.
Definition: Validator.php:15
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
eZ\Publish\Core\FieldType\Validator
Definition: EmailAddressValidator.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.