Answer the question
In order to leave comments, you need to log in
How to write a validator to determine the phone number, username or email. the address?
in the login model created the property $login displayed it in the form as "Phone number, username or e-mail address"
Help create a validator that will determine whether the user entered, phone, name, or email
Answer the question
In order to leave comments, you need to log in
in short then
public function rules()
{
return [
['login', 'validateLogin'],
];
}
public function validateLogin($attribute, $params, $validator)
{
if (!is_telephone($this->$attribute) && !is_email($this->$attribute) && !is_name($this->$attribute)) {
$this->addError($attribute, 'Должен быть емейлом, телефоном или именем');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question