-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
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
Request to support 'hostname' string validation #3589
Comments
Hi, first of all: I think this idea has potential in being implemented and used widely. However this can be widely interpreted, hi.how.are.you.google.com is a valid domain, but should it be a valid hostname? Or should only google.com or example.com be valid. Lets look at mozilla's definition on hostname: https://hello.world.example.com/ -> url.hostname = hello.world.example.com But should |
@m10rten Thanks for following up. I believe the value returned from
|
I further spent some time checking the RFC specification (https://datatracker.ietf.org/doc/html/rfc3986#autoid-21), As per the specifications, a valid hostname could be
|
Thanks for clearing that up! Maybe we can work with that, how do you see using it? And what would the result look like? Or exact like a |
I think it should be used similarly to existing zod string validations, such as email or uuid. As for the implementation options:
|
I've submitted a PR to add support for the hostname method in z.string() for enhanced validation. |
When is this going to get released? |
Issue:
I am working on a use case where I need to validate hostname strings before passing them to a database. While Zod supports URL validation, I could not find any built-in support for validating hostnames specifically.
For example, I need to validate strings such as:
Current Workaround:
Currently, I am using a regular expression to validate hostnames. However, having built-in support in Zod for hostname validation would be more efficient and reliable.
Request:
I would like to request the addition of hostname validation support in Zod, this would be beneficial. If this request makes sense, I am willing to contribute to adding this feature to the library.
The text was updated successfully, but these errors were encountered: