Skip to content

Proposal: Add domain() validator to Valibot #1277

@yslpn

Description

@yslpn

Proposal: Add domain() validator to Valibot

Summary

Add a built-in domain() validator to Valibot for validating FQDNs and second-level+ domains, with configurable options (Unicode/IDNA, TLD filtering, wildcard, trailing dot, etc.). This covers the common case “validate a domain, not a URL/email/localhost” without having to maintain complex regular expressions.

Prior discussions that were closed:

Please consider adding this validator to core or to an official extensions package.

Problem

Valibot provides email() and url(), but there is no validator specifically for domain names. As a result:

  • Consumers fall back to regex()/pattern(), which is:
    • hard to maintain and reuse,
    • easy to get wrong on edge cases (label length 1–63, overall length, hyphen rules, IDNA/Unicode, TLD constraints, etc.).
  • url() is too broad when only a bare domain (no scheme/path/port) is needed.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions