This commit is contained in:
xl
2023-07-07 17:24:03 +08:00
parent 448b1a68fc
commit d18994fde2
11 changed files with 310 additions and 342 deletions
+9 -16
View File
@@ -13,26 +13,19 @@ namespace validator;
class EmailValidator extends BaseValidator
{
/**
* @return bool
* 检查是否存在
*/
/**
* @return bool
* 检查是否存在
* @throws \ReflectionException
*/
public function trigger(): bool
{
return $this->_validator($this->field, function ($field, $params) {
$value = $params[$field] ?? null;
if (empty($value)) {
return true;
}
$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
if (!preg_match($exp, $value)) {
return $this->addError($field,'The param :attribute format error');
}
[$account, $domain] = explode("@", $value);
if (checkdnsrr($domain, "MX")) {
return true;
}
return $this->addError($field,'The param :attribute format error');
if (!filter_var($value,FILTER_VALIDATE_EMAIL)) {
return $this->addError($field,'The param :attribute format error');
}
return true;
}, $this->params);
}