Skip to content

.ip()

Passes when the whole string is an IP address of version, or of either version when version is null. IPv4 octets must not have leading zeros. IPv6 accepts :: compression, including ::1 and ::, and an embedded IPv4 address, but not a zone such as %eth0. IpVersion is an enum with v4 and v6.

StringValidator<O> ip({IpVersion? version, String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
version IpVersion? IpVersion.v4 or IpVersion.v6. Omit to accept either. params['version'].
message String? Replaces the default error message.
messageBuilder MessageBuilder? Builds the message from the issue. message wins when both are given. See Message builders.

Code invalidIp. Default message: value must be a valid IP address, IPv4 address, or IPv6 address, depending on version. value is replaced by the field name when there is one.

@IsIp(version: IpVersion.v4), or the constant @isIp for either version. Put the annotation on the constructor parameter or the field.

final v4 = l.string().ip(version: IpVersion.v4);
v4.validate(input)+1-2
  1. valid: '192.168.0.1'
  2. invalid: '::1'value must be a valid IPv4 address
  3. invalid: '999.1.1.1'value must be a valid IPv4 address
true
[value must be a valid IP address]
[value must be a valid IPv6 address]