protected function validateFormat($field, ?string $val, $format, $required = true)
    {
        if ($val !== null) {
            $regexp = $this->getKnownFormat($format);
            if (!$regexp) {
                $regexp = $format;
            }
            $result = preg_match($regexp, $val);
        } else {
            $result = !$required;
        }

        if ($result) {
            $this->clearError($field, 'validFormat');
            return true;
        } else {
            $error = [
                "title" => "Invalid Format for Field `$field`",
                "detail" => "Value for field `$field` must be a(n) $format."
            ];
            if ($format === $regexp) {
                $error["detail"] = "Value for field `$field` must match $format.";
            }
            $this->setError($field, 'validFormat', $error);
            return false;
        }
    }