Skip to main content

ipv4

$ipv4

Validates that a string is a valid IPv4 address in dotted-decimal notation.

Parameters

  • in (string, optional): Network range to validate against. Accepts CIDR notation (e.g. '192.168.1.0/24') or a named range: rfc1918, loopback, link-local, rfc6598, multicast, non-routable.
  • min (string, optional): Minimum IPv4 address (inclusive).
  • max (string, optional): Maximum IPv4 address (inclusive).
  • format (string, optional): Output format — 'integer' emits the address as a uint32. Default passes through the original dotted-decimal string.

Use either in OR min/max, not both.

Example

// Format-only validation
new Schema('string').validator('$ipv4')

// CIDR range (positional `in`)
new Schema('string').validator({$ipv4: '192.168.1.0/24'})

// Named range
new Schema('string').validator({$ipv4: 'rfc1918'})

// Explicit min/max
new Schema('string').validator({$ipv4: {min: '192.168.1.1', max: '192.168.1.254'}})

// Output as uint32
new Schema('string').validator({$ipv4: {in: 'rfc1918', format: 'integer'}})