diff --git a/examples/user-register.php b/examples/user-register.php index e185fba..e37fac0 100644 --- a/examples/user-register.php +++ b/examples/user-register.php @@ -10,7 +10,7 @@ $inputDate=[ "name" => "kuangweijian", "email" => "12345678@qq.com", - "hkPhoneNum"=> "012345678", + "hkPhoneNum"=> "", "password" => "1234567890", "pwdConfirm"=> "1234567890", ]; diff --git a/src/validators/HKPhoneNum.php b/src/validators/HKPhoneNum.php index 43591bc..8bee23f 100644 --- a/src/validators/HKPhoneNum.php +++ b/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} */ @@ -42,5 +53,6 @@ use yii\validators\Validator; } return $valid ? null : [$this->message, []]; } + } ?> \ No newline at end of file