Browse Source

增加validateAttribute()

master
kuangweijian 3 years ago
parent
commit
fcf5b559b7
  1. 2
      examples/user-register.php
  2. 12
      src/validators/HKPhoneNum.php

2
examples/user-register.php

@ -10,7 +10,7 @@
$inputDate=[ $inputDate=[
"name" => "kuangweijian", "name" => "kuangweijian",
"email" => "12345678@qq.com", "email" => "12345678@qq.com",
"hkPhoneNum"=> "012345678",
"hkPhoneNum"=> "",
"password" => "1234567890", "password" => "1234567890",
"pwdConfirm"=> "1234567890", "pwdConfirm"=> "1234567890",
]; ];

12
src/validators/HKPhoneNum.php

@ -28,6 +28,17 @@ use yii\validators\Validator;
} }
} }
/**
* {@inheritdoc}
*/
public function validateAttribute($model, $attribute)
{
$result = $this->validateValue($model->$attribute);
if (!empty($result)) {
$this->addError($model, $attribute, $result[0], $result[1]);
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -42,5 +53,6 @@ use yii\validators\Validator;
} }
return $valid ? null : [$this->message, []]; return $valid ? null : [$this->message, []];
} }
} }
?> ?>
Loading…
Cancel
Save