table = $table; // 当前的集合表 $this->siteAliasName = $siteAliasName; // 站点别名 $this->params = (isset($ruleValue['params']) && !empty($ruleValue['params'])) ? $ruleValue['params'] : ''; $this->message = (isset($ruleValue['error_msg']) && !empty($ruleValue['error_msg'])) ? $ruleValue['error_msg'] : ''; } /** * Determine if the validation rule passes. * * @param $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value): bool { $chars = "/^((\(\d{2,3}\))|(\d{3}\-))?1\d{10}$/"; if (preg_match($chars, $value)) { return true; } else { return false; } } /** * Get the validation error message. * * @return string|null */ public function message(): ?string { return $this->message ?: '该手机号不正确!'; } }