使用正则验证数据
@access public
@param string $value  要验证的数据
@param string $rule 验证规则
@return boolean
777231
public function regex($value,$rule) {
        $validate = array(
            'require'   =>  '/\S+/',
            'email'     =>  '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
            'url'       =>  '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
            '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;
    }
558024
public function confirm( $value, $rule, $data = [], $field = '' )
	{
		if( '' == $rule ){
			if( strpos( $field, '_confirm' ) ){
				$rule = strstr( $field, '_confirm', true );
			} else{
				$rule = $field.'_confirm';
			}
		}
		return $this->getDataValue( $data, $rule ) === $value;
	}
704016
public static function regexMatch(string $value, string $rule): bool
    {
        $validate = [
            '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]+$/',
        ];

        $value = \trim($value);
        $name  = \strtolower($rule);

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

        return \preg_match($rule, $value) === 1;
    }
856747
public function check($value, $rule, AppliesToResource $resource=null)
    {

        $constraints = $this->ruleToArray($rule);

        foreach ($constraints as $name => $parameters) {

            $arguments = $parameters;

            array_unshift($arguments, $value);

            if ($resource) {
                $arguments[] = $resource;
            }

            if (!$this->__call($name, $arguments)) {
                return false;
            }
        }

        return true;
    }
472591
protected function in($value, $rule)
    {
        return in_array($value, is_array($rule) ? $rule : explode(',', $rule));
    }
1143163
public function applyFilters($value, $rules = array())
    {
        $valueTO = $this->valueTO->forge($value);
        // loop through all the rules to validate $value.
        foreach ($rules as $rule => $parameter) {
            // skip rules with option as FALSE.
            if ($parameter === false) {
                continue;
            }
            $this->filter->apply($rule, $valueTO, $parameter);

            // loop break.
            if ($valueTO->getBreak()) {
                break;
            }
        }

        return $valueTO;
    }
1180786
public function check($rule = []) {
		$rule = $rule ?: $this->validate;

		/* 检查文件大小 */
		if (isset($rule['size']) && !$this->checkSize($rule['size'])) {
			$this->error = '上传文件大小不符！';
			return false;
		}

		/* 检查文件Mime类型 */
		if (isset($rule['type']) && !$this->checkMime($rule['type'])) {
			$this->error = '上传文件MIME类型不允许！';
			return false;
		}

		/* 检查文件后缀 */
		if (isset($rule['ext']) && !$this->checkExt($rule['ext'])) {
			$this->error = '上传文件后缀不允许';
			return false;
		}

		/* 检查图像文件 */
		if (!$this->checkImg()) {
			$this->error = '非法图像文件！';
			return false;
		}

		return true;
	}
937451
private function validateByRule( $field, $value, $rule, $message = null )
    {
        $ruleClassName = $this->ruleToClassName($this->getRuleName($rule));

        if (!class_exists($ruleClassName)) {
            return false;
        }

        $ruleObject = new $ruleClassName();
        if ($this->isLengthRule($rule)) {
            $ruleObject->setLength($this->extractLength($rule));;
        } else {
            if ($this->isSameRule($rule)) {
                $ruleObject->prepareRule($this->fields, $this->extractSame($rule));
            }
        }
        $result = $ruleObject->run($this->keyToLabel($field), $value, $message);

        if (!$result) {
            static::$errors[ $field ] = $ruleObject->message();
        }

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

        return !is_null($val) && $value < $val;
    }
362190
public function apply(Rule $rule, $value)
    {
        $type = $rule->getInputType();

        if ($type == CallbackRule::SELF_METHOD_TYPE) {
            return $this->useObjectMethod($rule->callback, $value);
        }

        if ($type == CallbackRule::CALLABLE_TYPE) {
            return $this->useCallable($rule->callback, $value);
        }

        if ($type == CallbackRule::CLOSURE_TYPE) {
            return $this->useClosure($rule->callback, $value);
        }

        throw new InvalidCallbackException("Unsupported callback provided, failed to filter property");
    }
875192
public function apply(Rule $rule, $value)
    {
        //trim() only operates in default mode
        //if no second argument is passed, it
        //cannot be passed as null
        if ($rule->charlist === null) {
            return trim($value);
        }

        return trim($value, $rule->charlist);
    }
1162705
private static function validateRegex($value, $pattern, Validator $validator)
    {
        if (!is_string($value) || preg_match($pattern, $value) === 1) {
            return null;
        }

        return error('The value {data} must match the format {parameter}.', $validator);
    }
1324837
protected function ip($value, $rule)
    {
        if (!in_array($rule, ['ipv4', 'ipv6'])) {
            $rule='ipv4';
        }
        return $this->filter($value, [FILTER_VALIDATE_IP, 'ipv6' == $rule ? FILTER_FLAG_IPV6 : FILTER_FLAG_IPV4]);
    }
609242
protected function egt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value >= $val;
    }
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;
        }
    }
1273334
public function setRule($rule)
    {
        if ('$' == substr($rule, -1, 1)) {
            // 是否完整匹配
            $rule = substr($rule, 0, -1);

            $this->option['complete_match'] = true;
        }

        $rule = '/' != $rule ? ltrim($rule, '/') : '';

        if ($this->parent && $prefix = $this->parent->getFullName()) {
            $rule = $prefix . ($rule ? '/' . ltrim($rule, '/') : '');
        }

        if (false !== strpos($rule, ':')) {
            $this->rule = preg_replace(['/\[\:(\w+)\]/', '/\:(\w+)/'], ['<\1?>', '<\1>'], $rule);
        } else {
            $this->rule = $rule;
        }

        // 生成路由标识的快捷访问
        $this->setRuleName();
    }
111928
public function checkRule($value, $rules)
    {
        if ($rules instanceof \Closure) {
            return call_user_func_array($rules, [$value]);
        } elseif ($rules instanceof ValidateRule) {
            $rules = $rules->getRule();
        } elseif (is_string($rules)) {
            $rules = explode('|', $rules);
        }

        foreach ($rules as $key => $rule) {
            if ($rule instanceof \Closure) {
                $result = call_user_func_array($rule, [$value]);
            } else {
                // 判断验证类型
                list($type, $rule) = $this->getValidateType($key, $rule);

                $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type];

                $result = call_user_func_array($callback, [$value, $rule]);
            }

            if (true !== $result) {
                return $result;
            }
        }

        return true;
    }