CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()semver()pick()ip(), ipv4(), ipv6()uuid(), guid()Chainable MethodsRefinementsError HandlingSchema CompositionSecurityCustom Validators
CLI Overviewctroenv validatectroenv generatectroenv checkctroenv docsctroenv initCLI Configuration
Node AdapterVite AdapterNext.js Adapter
Migration from t3-envMigration from envalidMigration from dotenv

ip(), ipv4(), ipv6()

Create IP address validators that accept IPv4, IPv6, or both.

  1. Docs
  2. Core API

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:

InputResult
"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:

InputResult
"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:

InputResult
"::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?

Edit on GitHub

Last updated on Jun 25, 2026

Previouspick()Nextuuid(), guid()

On this page

SignatureAccepted Values`ip()``ipv4()``ipv6()`RefinementsExamplesBasic IP validationCombined with secret