# pydantic.errors.EmailError: 值不是有效的电子邮件地址

- **ID:** `python/pydantic-email-format-invalid`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 EmailStr 类型时，输入字符串不符合电子邮件格式（例如缺少 @、域名无效）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Use EmailStr from pydantic: email: EmailStr
   ```
2. **** (90% 成功率)
   ```
   Sanitize input before validation: @field_validator('email', mode='before') def clean(cls, v): return v.strip()
   ```

## 无效尝试

- **** — Custom regex may not capture all email edge cases, leading to false positives. (60% 失败率)
- **** — Empty string is not a valid email, even if optional. (70% 失败率)
