Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UserValidationRules.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\User\Model;
8 
13 
21 {
26 
33  public function addUserInfoRules(\Magento\Framework\Validator\DataObject $validator)
34  {
35  $userNameNotEmpty = new NotEmpty();
36  $userNameNotEmpty->setMessage(
37  __('"User Name" is required. Enter and try again.'),
39  );
40  $firstNameNotEmpty = new NotEmpty();
41  $firstNameNotEmpty->setMessage(
42  __('"First Name" is required. Enter and try again.'),
44  );
45  $lastNameNotEmpty = new NotEmpty();
46  $lastNameNotEmpty->setMessage(
47  __('"Last Name" is required. Enter and try again.'),
49  );
50  $emailValidity = new EmailAddress();
51  $emailValidity->setMessage(
52  __('Please enter a valid email.'),
54  );
55 
57  $validator->addRule(
58  $userNameNotEmpty,
59  'username'
60  )->addRule(
61  $firstNameNotEmpty,
62  'firstname'
63  )->addRule(
64  $lastNameNotEmpty,
65  'lastname'
66  )->addRule(
67  $emailValidity,
68  'email'
69  );
70 
71  return $validator;
72  }
73 
80  public function addPasswordRules(\Magento\Framework\Validator\DataObject $validator)
81  {
82  $passwordNotEmpty = new NotEmpty();
83  $passwordNotEmpty->setMessage(__('Password is required field.'), NotEmpty::IS_EMPTY);
84  $minPassLength = self::MIN_PASSWORD_LENGTH;
85  $passwordLength = new StringLength(['min' => $minPassLength, 'encoding' => 'UTF-8']);
86  $passwordLength->setMessage(
87  __('Your password must be at least %1 characters.', $minPassLength),
89  );
90  $passwordChars = new Regex('/[a-z].*\d|\d.*[a-z]/iu');
91  $passwordChars->setMessage(
92  __('Your password must include both numeric and alphabetic characters.'),
94  );
95  $validator->addRule(
96  $passwordNotEmpty,
97  'password'
98  )->addRule(
99  $passwordLength,
100  'password'
101  )->addRule(
102  $passwordChars,
103  'password'
104  );
105 
106  return $validator;
107  }
108 
117  \Magento\Framework\Validator\DataObject $validator,
118  $passwordConfirmation
119  ) {
120  $passwordConfirmation = new \Zend_Validate_Identical($passwordConfirmation);
121  $passwordConfirmation->setMessage(
122  __('Your password confirmation must match your password.'),
124  );
125  $validator->addRule($passwordConfirmation, 'password');
126  return $validator;
127  }
128 }
addPasswordConfirmationRule(\Magento\Framework\Validator\DataObject $validator, $passwordConfirmation)
addPasswordRules(\Magento\Framework\Validator\DataObject $validator)
__()
Definition: __.php:13