Skip to content

feat: add domain, URL and email validators#2167

Open
seladb wants to merge 2 commits intotortoise:developfrom
seladb:add-validators
Open

feat: add domain, URL and email validators#2167
seladb wants to merge 2 commits intotortoise:developfrom
seladb:add-validators

Conversation

@seladb
Copy link
Copy Markdown
Contributor

@seladb seladb commented Apr 4, 2026

Added new validators: DomainNameValidator, URLValidator, and EmailValidator heavily inspired by the corresponding Django validators

Description

Added three new validator classes:

  1. DomainNameValidator - Validates domain names according to RFC 1034 and RFC 1123
    • Supports internationalized domain names (IDN) via accept_idna parameter
    • Includes InvalidDomainName exception class
  2. URLValidator - Validates URLs according to RFC 3986
    • Supports IPv4, IPv6 addresses, ports, and various schemes (http, https, ftp, ftps)
    • Includes InvalidURL and InvalidScheme exception classes
  3. EmailValidator - Validates email addresses according to RFC 3696
    • Validates both local part and domain part
    • Supports domain allowlisting via allowed_domains parameter
    • Supports literal IPv4/IPv6 addresses in domain
    • Includes InvalidEmailAddress exception class

Also added:

  • Pre-configured validator instances: validate_domain_name, validate_url, validate_email
  • Comprehensive tests

Motivation and Context

Provides built-in validators for common validation patterns (domain names, URLs, email addresses) that can be used in tortoise-orm field validators.

Also in par with Django validators.

How Has This Been Tested?

  • Added new test cases unser pytest tests/test_validators.py covering valid and invalid inputs for all three validators

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 4, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing seladb:add-validators (033ce38) with develop (2df46d0)

Open in CodSpeed

@seladb seladb changed the title Add domain, URL and email validators feat: Add domain, URL and email validators Apr 4, 2026
@seladb seladb changed the title feat: Add domain, URL and email validators feat: add domain, URL and email validators Apr 4, 2026
@seladb seladb marked this pull request as ready for review April 4, 2026 08:41
@seladb
Copy link
Copy Markdown
Contributor Author

seladb commented Apr 4, 2026

@abondar MSSQL tests are failing again 😕
Can we disable the failing tests for now so we merge PRs that are not related?
Or maybe give me permissions to re-run the failing tests?

@seladb
Copy link
Copy Markdown
Contributor Author

seladb commented Apr 4, 2026

Also @abondar @long2ice I have 5 PRs ready for review, some of them are ready for quite some time. Do you accept PRs in this project and are available to review them? If yes, I'd really appreciate if you can review.

I really like this project and would love to contribute more! ❤️

@seladb
Copy link
Copy Markdown
Contributor Author

seladb commented Apr 5, 2026

@abondar MSSQL tests are failing again 😕 Can we disable the failing tests for now so we merge PRs that are not related? Or maybe give me permissions to re-run the failing tests?

@abondar I think I found the bug! I created a PR with a fix here: #2169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant