# JSON Schema验证失败：格式'email'拒绝带有加号或国际字符的有效电子邮件

- **ID:** `data/json-schema-format-email-validation-failure`
- **领域:** data
- **类别:** validation_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

JSON Schema内置的'email'格式验证使用不支持现代电子邮件功能（如加号地址、国际化域名）的正则表达式，导致误报。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| JSON Schema Draft-07 | active | — | — |
| Ajv 8.12.0 | active | — | — |
| Python jsonschema 4.20.0 | active | — | — |
| OpenAPI 3.1.0 | active | — | — |

## 解决方案

1. ```
   Use a custom format validator that follows RFC 5321/5322. In Python with jsonschema, register a custom validator: `import re; email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'; jsonschema.validators.create(meta_schema=..., validators={'format': lambda v, f, s: ...})`
   ```
2. ```
   In Ajv (JavaScript), use `ajv.addFormat('email', /^[^\s@]+@[^\s@]+\.[^\s@]+$/)` to override the default email format with a more permissive regex
   ```
3. ```
   Switch to a validation library that supports RFC-compliant email validation, such as 'email-validator' in Python, and apply it as a custom keyword in the schema
   ```

## 无效尝试

- **** — Writing a custom regex that correctly validates all valid email addresses is extremely complex and often introduces new bugs (e.g., rejecting valid addresses or allowing invalid ones). (70% 失败率)
- **** — This disables all email validation, allowing any string to pass, which defeats the purpose of schema validation and may lead to downstream errors. (80% 失败率)
- **** — Not all validators support 'idn-email', and it still may reject plus signs or other common email features. (60% 失败率)
