Files

33 lines
573 B
PHP
Raw Permalink Normal View History

2021-08-11 15:13:35 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/20 0020
* Time: 17:32
*/
declare(strict_types=1);
namespace validator;
class EmailValidator extends BaseValidator
{
2022-01-04 16:53:31 +08:00
2021-08-11 15:13:35 +08:00
/**
* @return bool
* 检查是否存在
*/
public function trigger(): bool
{
2022-01-04 16:53:31 +08:00
if (empty($this->params) || !isset($this->params[$this->field])) {
return true;
}
if (preg_match('/^[a-zA-Z0-9]+([\.\_]{1,})[a-zA-Z0-9]+@[a-zA-Z]+(\.\w+)+/', $this->params[$this->field])) {
2021-08-11 15:13:35 +08:00
return true;
} else {
2022-01-04 16:53:31 +08:00
return $this->addError('The param :attribute format error');
2021-08-11 15:13:35 +08:00
}
}
2022-01-04 16:53:31 +08:00
2021-08-11 15:13:35 +08:00
}