ip(), ipv4(), ipv6()
Create IP address validators that accept IPv4, IPv6, or both.
ip(), ipv4(), ipv6()
Creates validators that accept IP address strings.
Signature
function ip(): IpValidator
function ipv4(): IpValidator
function ipv6(): IpValidator
Accepted Values
ip()
Accepts valid IPv4 or IPv6 addresses:
| Input | Result |
|---|---|
"192.168.1.1" | ✅ |
"::1" | ✅ |
"2001:db8::1" | ✅ |
"10.0.0.1" | ✅ |
"localhost" | ❌ Not an IP |
"256.0.0.1" | ❌ Invalid IPv4 octet |
ipv4()
Accepts only strict IPv4 dotted-decimal addresses:
| Input | Result |
|---|---|
"192.168.1.1" | ✅ |
"127.0.0.1" | ✅ |
"0.0.0.0" | ✅ |
"::1" | ❌ IPv6 not accepted |
"localhost" | ❌ Not an IP |
"10.0" | ❌ Incomplete |
ipv6()
Accepts only strict RFC 3986 IPv6 addresses. Zone indices (like %eth0) are rejected:
| Input | Result |
|---|---|
"::1" | ✅ |
"2001:db8::1" | ✅ |
"fe80::1" | ✅ |
"fe80::1%eth0" | ❌ Zone index rejected |
"192.168.1.1" | ❌ IPv4 not accepted |
"::" | ✅ Unspecified address |
Refinements
IP validators have no type-specific refinements. They support only the chainable methods (.optional(), .default(), .describe(), .secret(), .validate()).
Examples
Basic IP validation
const env = defineEnv({
BIND_ADDRESS: ip(),
PRIMARY_DNS: ipv4(),
LINK_LOCAL: ipv6().optional(),
})
Combined with secret
const env = defineEnv({
PROXY_IP: ip().secret(),
})How is this guide?
Last updated on Jun 25, 2026