email: Optional[str] = Query(..., description="email", min_length=10, max_length=50,regex="^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$")
result
{
"detail": [
{
"loc": [
"query",
"email"
],
"msg": "string does not match regex \"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$\"",
"type": "value_error.str.regex",
"ctx": {
"pattern": "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"
}
}
]
}
"msg": "string does not match regex \"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$\""
I think it's ugly
How to custom
You can use EmailStr from Pydantic:
from pydantic import EmailStr
Is the problem resolved @dyhawks? If it is, do you mind closing the issue then?
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.
Thanks for the help here @Kludex and @ycd ! :clap: :bow:
Most helpful comment
You can use
EmailStrfrom Pydantic: