.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.
Signature
Section titled “Signature”StringValidator<O> ip({IpVersion? version, String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”@IsIp(version: IpVersion.v4), or the constant @isIp for either version. Put the annotation on the constructor parameter or the field.
Example
Section titled “Example”final v4 = l.string().ip(version: IpVersion.v4);@IsIp(version: IpVersion.v4) required String host, // l.string().ip(version: IpVersion.v4).required()@isIp String? peer, // l.string().ip()v4.validate(input)+1-2- valid:
'192.168.0.1' - invalid:
'::1' - invalid:
'999.1.1.1'
true[value must be a valid IP address][value must be a valid IPv6 address]