core/Validate.php
public function checkField(Field $field)
    {
        if (Validate::$default_errors == null) {
            Validate::$default_errors = Config::get('form.validate_default_errors', []);
        }
        if (!empty($field->error)) {
            return false;
        }
        if ($field->dataValDisabled) {
            return true;
        }
        if (!empty($field->childError)) {
            return false;
        }
        $value = $field->value;
        $validFunc = $field->getFunc('valid');
        if ($validFunc && is_callable($validFunc)) {
            $error = $validFunc($value);
            if (!empty($error)) {
                $field->error = $error;
                return false;
            }
        }
        $rules = $field->dataValRule;
        if ($rules == null) {
            return true;
        }
        $errors = $field->dataValMessage;
        if ($errors == null) {
            $errors = [];
        }
        $tempErrors = [];
        foreach ($errors as $type => $err) {
            $realType = Validate::getRealType($type);
            $tempErrors[$realType] = $err;
        }
        $errors = $tempErrors;
        $tempRules = [];
        foreach ($rules as $type => $args) {
            $realType = Validate::getRealType($type);
            $tempRules[$realType] = $args;
        }
        $rules = $tempRules;
        //验证非空
        if (isset($rules['required']) && $rules['required']) {
            $func = isset($this->func['required']) ? $this->func['required'] : Validate::getFunc('required');
            $r = call_user_func_array($func, [$value]);
            if (!$r) {
                $err = isset($this->def_errors['required']) ? $this->def_errors['required'] : (isset($errors['required']) ? $errors['required'] : (isset(Validate::$default_errors['required']) ? Validate::$default_errors['required'] : '必填项'));
                $field->error = $err;
                return false;
            }
            unset($rules['required']);
        }
        if (is_array($value)) {
            return true;
        }
        if (strlen($value) > 0 || (isset($rules['force']) && $rules['force'])) {
            unset($rules['force']);
            foreach ($rules as $type => $args) {
                if (!is_array($args)) {
                    $args = [$args];
                }
                $param = array_slice($args, 0);
                array_unshift($args, $value);
                $func = isset($this->func[$type]) ? $this->func[$type] : Validate::getFunc($type);
                if ($func == null) {
                    continue;
                }
                $out = call_user_func_array($func, $args);
                if (is_bool($out)) {
                    if ($out) {
                        continue;
                    }
                    $err = isset($this->def_errors[$type]) ? $this->def_errors[$type] : (isset($errors[$type]) ? $errors[$type] : (isset(Validate::$default_errors[$type]) ? Validate::$default_errors[$type] : '格式错误'));
                    $field->error = Validate::format($err, $param);
                    return false;
                }
                if (is_array($out) && isset($out['status']) && !$out['status'] && !empty($out['error'])) {
                    $field->error = Validate::format($out['error'], $param);
                    return false;
                }
            }
        }
        return true;
    }
public function checkField(Field $field)
    {
        if (Validate::$default_errors == null) {
            Validate::$default_errors = Config::get('form.validate_default_errors', []);
        }
        if (!empty($field->error)) {
            return false;
        }
        if ($field->dataValDisabled) {
            return true;
        }
        if (!empty($field->childError)) {
            return false;
        }
        $value = $field->value;
        $validFunc = $field->getFunc('valid');
        if ($validFunc && is_callable($validFunc)) {
            $error = $validFunc($value);
            if (!empty($error)) {
                $field->error = $error;
                return false;
            }
        }
        $rules = $field->dataValRule;
        if ($rules == null) {
            return true;
        }
        $errors = $field->dataValMessage;
        if ($errors == null) {
            $errors = [];
        }
        $tempErrors = [];
        foreach ($errors as $type => $err) {
            $realType = Validate::getRealType($type);
            $tempErrors[$realType] = $err;
        }
        $errors = $tempErrors;
        $tempRules = [];
        foreach ($rules as $type => $args) {
            $realType = Validate::getRealType($type);
            $tempRules[$realType] = $args;
        }
        $rules = $tempRules;
        //验证非空
        if (isset($rules['required']) && $rules['required']) {
            $func = isset($this->func['required']) ? $this->func['required'] : Validate::getFunc('required');
            $r = call_user_func_array($func, [$value]);
            if (!$r) {
                $err = isset($this->def_errors['required']) ? $this->def_errors['required'] : (isset($errors['required']) ? $errors['required'] : (isset(Validate::$default_errors['required']) ? Validate::$default_errors['required'] : '必填项'));
                $field->error = $err;
                return false;
            }
            unset($rules['required']);
        }
        if (is_array($value)) {
            return true;
        }
        if (strlen($value) > 0 || (isset($rules['force']) && $rules['force'])) {
            unset($rules['force']);
            foreach ($rules as $type => $args) {
                if (!is_array($args)) {
                    $args = [$args];
                }
                $param = array_slice($args, 0);
                array_unshift($args, $value);
                $func = isset($this->func[$type]) ? $this->func[$type] : Validate::getFunc($type);
                if ($func == null) {
                    continue;
                }
                $out = call_user_func_array($func, $args);
                if (is_bool($out)) {
                    if ($out) {
                        continue;
                    }
                    $err = isset($this->def_errors[$type]) ? $this->def_errors[$type] : (isset($errors[$type]) ? $errors[$type] : (isset(Validate::$default_errors[$type]) ? Validate::$default_errors[$type] : '格式错误'));
                    $field->error = Validate::format($err, $param);
                    return false;
                }
                if (is_array($out) && isset($out['status']) && !$out['status'] && !empty($out['error'])) {
                    $field->error = Validate::format($out['error'], $param);
                    return false;
                }
            }
        }
        return true;
    }
字段检查
@param Field $field
@return bool