zod
zod copied to clipboard
feat: added support for hostname method in z.string() #3589
Added support for the hostname method in z.string() for enhanced string validation. This feature introduces a dedicated method to validate domain names, including Punycode, as well as IPv4 and IPv6 addresses(in square brackets). The new validation method ensures that valid hostnames meet the appropriate criteria and excludes invalid patterns.
This implementation was done for ticket #3589.
Changes:
Implemented the hostname method to validate: Domain names, including those encoded in Punycode. IPv4 addresses. IPv6 addresses enclosed in square brackets. Updated regex patterns to accurately handle valid and invalid hostname cases. Added comprehensive test cases to ensure robustness and correctness of the new validation method. Updated documentation to include details about the hostname method and usage examples.