使用正则验证数据
@access public
@param string $value 要验证的数据
@param string $rule 验证规则 require email url currency number integer english
@return boolean
322879
public static function regexVerify($value, $rule)
    {
        $value = trim($value);
        $validate = array(
            'require' => '/\S+/',
            'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
            // 'url'       =>  '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
            'url' => '/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i',
            'currency' => '/^\d+(\.\d+)?$/',
            # 货币
            'number' => '/^\d+$/',
            'zip' => '/^\d{6}$/',
            'integer' => '/^[-\+]?\d+$/',
            'double' => '/^[-\+]?\d+(\.\d+)?$/',
            'english' => '/^[A-Za-z]+$/',
        );

        // 检查是否有内置的正则表达式
        if (isset($validate[strtolower($rule)])) {
            $rule = $validate[strtolower($rule)];
        }

        return preg_match($rule, $value) === 1;
    }
906627
public function unique($value, $rule, $data, $field) {
        if (is_string($rule)) {
            $rule = explode(',', $rule);
        }

        if (false !== strpos($rule[0], '\\')) {
            // 指定模型类
            $db = new $rule[0];
        }
        else {
            try {
                $db = Container::get('app')->model($rule[0]);
            }
            catch (ClassNotFoundException $e) {
                $db = Db::name($rule[0]);
            }
        }

        $key = isset($rule[1]) ? $rule[1] : $field;

        if (strpos($key, '^')) {
            // 支持多个字段验证
            $fields = explode('^', $key);
            foreach ($fields as $key) {
                $map[] = [$key, '=', $data[$key]];
            }
        }
        else {
            $map[] = [$key, '=', $data[$field]];
        }

        $pk = !empty($rule[3]) ? $rule[3] : $db->getPk();

        if (is_string($pk)) {
            if (isset($rule[2])) {
                $map[] = [$pk, '<>', $rule[2]];
            }
            elseif (isset($data[$pk])) {
                $map[] = [$pk, '<>', $data[$pk]];
            }
        }

        if ($db->where($map)->field($pk)->find()) {
            return false;
        }

        return true;
    }
492549
protected function allowIp($value, $rule)
    {
        return in_array($_SERVER['REMOTE_ADDR'], is_array($rule) ? $rule : explode(',', $rule));
    }
1212686
private function match_regex($value, $pattern, $rules = array())
    {
        $pieces = explode(':', $pattern);
        if(count($pieces) <= 1)
            return false;

        $regex = $pieces[1];

        if (array_key_exists($regex, $rules)) {
            $regex = $rules[$regex];
        }

        // ritorna vero se il valore
        // rispetta l'espressione regolare
        return preg_match( "/$regex/", $value );
    }
200502
protected function length($value, $rule)
    {
        if (is_array($value)) {
            $length=count($value);
        } elseif ($value instanceof File) {
            $length=$value->getSize();
        } else {
            $length=mb_strlen((string) $value);
        }

        if (strpos($rule, ',')) {
            // 长度区间
            list($min, $max)=explode(',', $rule);
            return $length >= $min && $length <= $max;
        } else {
            // 指定长度
            return $length == $rule;
        }
    }
823591
private function _check($value, $rule_type, $rule_value)
    {
        switch ($rule_type) {
            case 'required':
                return !empty($value);
                break;
            case 'func':
                return call_user_func($rule_value, $value);
                break;
            case 'regex':
                return $this->match($value, $rule_value);
                break;
            case 'type':
                return $this->$rule_value($value);
                break;
            case 'max':
            case 'min':
            case 'range':
            case 'in':
                return $this->$rule_type($value, $rule_value);
                break;
            default:
                return true;
        }
    }
920279
public function isValidValue($rules, $value) {
        $result = [];
        foreach ($rules as $rule) {
            $parameters = $rule;
            $name       = array_shift($parameters);
            $valid      = $this->isValidRule($name, $parameters, $value);
            if ($valid !== null) {
                $result[] = $valid;
            }
        }
        return $result;
    }
1233563
public function parse($value, $rule) {
        $this->formatEnumRule($rule);

        $this->formatEnumValue($value, $rule);

        return $value;
    }
745738
protected function checkRegex($value, $rule) {

        if (0 !== strpos($rule, '/') && !preg_match('/\/[imsU]{0,4}$/', $rule)) {
            // 不是正则表达式则两端补上/
            $rule = '/^' . $rule . '$/';
        }
        return is_scalar($value) && 1 === preg_match($rule, (string)$value);
    }
1019123
protected function notIn($value, $rule)
    {
        return !in_array($value, is_array($rule) ? $rule : explode(',', $rule));
    }
461181
public function check($value) : bool
    {
        try {
            if (false == \DateTime::createFromFormat($this->rule, $value)) {
                return false;
            }
            return true;
        } catch (\Exception $e) {
            return false;
        }
    }
597733
public function validate($attribute, $rules, $value)
    {
        if (is_int($value)) {
            $value = (string)$value;
        } elseif (is_bool($value)) {
            $value = $value ? '1' : '0';
        } elseif ($value === null) {
            $value = '';
        }

        foreach ($rules as $k => $v) {
            if (is_int($k)) {
                $value = $this->_validate($attribute, $v, [], $value);
            } else {
                $value = $this->_validate($attribute, $k, is_array($v) ? $v : explode('-', $v), $value);
            }
        }

        return $value;
    }
135964
protected function lt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value < $val;
    }
803716
public static function email(string $value): bool
    {
        $result = filter_var($value, FILTER_VALIDATE_EMAIL);
        return is_string($result) && $value === $result;
    }
1078177
public function is( $value, $rule, $data = [] )
	{
		switch( Loader::parseName( $rule, 1, false ) ){
		case 'require':
			// 必须
			$result = !empty( $value ) || '0' == $value;
		break;
		case 'accepted':
			// 接受
			$result = in_array( $value, ['1', 'on', 'yes'] );
		break;
		case 'date':
			// 是否是一个有效日期
			$result = false !== strtotime( $value );
		break;
		case 'activeUrl':
			// 是否为有效的网址
			$result = checkdnsrr( $value );
		break;
		case 'boolean':
		case 'bool':
			// 是否为布尔值
			$result = in_array( $value, [true, false, 0, 1, '0', '1'], true );
		break;
		case 'number':
			$result = is_numeric( $value );
		break;
		case 'array':
			// 是否为数组
			$result = is_array( $value );
		break;
		case 'file':
			$result = isset( $value['name'] ) && isset( $value['type'] ) && isset( $value['tmp_name'] ) && isset( $value['error'] ) && isset( $value['size'] );
		break;
		case 'image':
			$result = isset( $value['name'] ) && isset( $value['type'] ) && isset( $value['tmp_name'] ) && isset( $value['error'] ) && isset( $value['size'] ) && in_array( $this->getImageType( $value->getRealPath() ), [1, 2, 3, 6] );
		break;
		case 'token':
			$result = $this->token( $value, '__token__', $data );
		break;
		case 'integer':
			// 是否为整型
			$result = $this->filter( $value, FILTER_VALIDATE_INT );
		break;
		case 'json':
			// 是否为json
			$result = $this->json( $value );
		break;
		case 'phone':
			$result = $this->phone( $value );
		break;
			//TODO email
		default:
			if( isset( self::$type[$rule] ) ){
				// 注册的验证规则
				$result = call_user_func_array( self::$type[$rule], [$value] );
			} elseif( isset( $this->filter[$rule] ) ){
				// Filter_var验证规则
				$result = $this->filter( $value, $this->filter[$rule] );
			} else{
				// 正则验证
				$result = $this->regex( $value, $rule );
			}
		}
		return $result;
	}
726675
public function ruleValue($value = null)
    {
        if (\func_num_args() > 0) {
            if (null !== $value && $this->validateValue($value)) {
                $this->value = $value;
                $this->updateBound();

                return true;
            }
            return false;
        }
        return $this->value;
    }
673842
public function valid($value)
    {

        foreach($this->getRules() as $index => $rule) {

            // check for required
            if (in_array($value, ['', null]) && !$this->hasRule('required')) {
                continue;
            }

            // extract params
            list($method, $params) = $rule;

            // If method is null, we use the index as the method name
            $method = is_null($method) ? $index : $method;

            // Build the params
            array_unshift($params, $value);

            // If it's a anonymous function
            if (!is_string($method) && is_callable($method)) {

                if (!call_user_func_array($method, $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }

            } else {// if it's a local method

                if (!method_exists($this, $method)) {
                    throw new \Exception('Method "'. $method .'" not found for validator : ' . $index);
                }

                if (!call_user_func_array([$this, $method], $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }
            }
        }

        return $this;
    }