We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
from pydantic import BaseModel, StringConstraints, ValidationError from typing import Annotated DomainStr = Annotated[str, StringConstraints(strip_whitespace=True, to_lower=True, min_length=1, max_length=253, pattern=r"^([a-z0-9-]+(\.[a-z0-9-]+)+)$")] class MyModel(BaseModel): url: DomainStr MyModel(url="google.com") # Passes MyModel(url="x.com") # Passes MyModel(url="www.a.co") # Passes try: MyModel(url="https://google.com") # Raises ValidationError except ValidationError: print("Raised validation error for http/s scheme") pass try: MyModel(url="file:///etc/passwd") # Raises ValidationError except ValidationError: print("Raised validation error for file scheme") pass``` ### Affected Components - [ ] [Compatibility between releases](https://docs.pydantic.dev/changelog/) - [ ] [Data validation/parsing](https://docs.pydantic.dev/concepts/models/#basic-model-usage) - [ ] [Data serialization](https://docs.pydantic.dev/concepts/serialization/) - `.model_dump()` and `.model_dump_json()` - [ ] [JSON Schema](https://docs.pydantic.dev/concepts/json_schema/) - [ ] [Dataclasses](https://docs.pydantic.dev/concepts/dataclasses/) - [ ] [Model Config](https://docs.pydantic.dev/concepts/config/) - [X] [Field Types](https://docs.pydantic.dev/api/types/) - adding or changing a particular data type - [ ] [Function validation decorator](https://docs.pydantic.dev/concepts/validation_decorator/) - [ ] [Generic Models](https://docs.pydantic.dev/concepts/models/#generic-models) - [ ] [Other Model behaviour](https://docs.pydantic.dev/concepts/models/) - `model_construct()`, pickling, private attributes, ORM mode - [ ] [Plugins](https://docs.pydantic.dev/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.
The text was updated successfully, but these errors were encountered:
I can open a PR for the DomainStr if everything is okay 😁
Sorry, something went wrong.
Feel free to open against pydantic-extra-types!
pydantic-extra-types
Added PR #212
Fixed here #212 Thank you @matter1-git
No branches or pull requests
Initial Checks
Description
The text was updated successfully, but these errors were encountered: