Skip to content
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
2 participants