Skip to content

The Field regex attribute was renamed pattern in pydantic v2 #1298

Discussion options

You must be logged in to vote

I ended doing even another way. Based on EmailStr from pydantic and this answer: https://stackoverflow.com/a/67871116

from typing import Annotated
from pydantic import StringConstraints
from sqlmodel import Field, SQLModel

LicencePlate = Annotated[str, StringConstraints(pattern=r"\w-\w{3}-\w{3}")]

class Car(SQLModel):
    license_plate: LicensePlate

It seems cleaner like this and I can reuse the type.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@YuriiMotov
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants