isIPv4 property

bool get isIPv4

Returns true if string matches IPv4 format.

final str1 = "203.120.223.13";
final str2 = "xyz";
str1.isIPv4;  // true
str2.isIPv4;  // false

Implementation

bool get isIPv4 => RegExp(r"^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$",
        caseSensitive: false)
    .hasMatch(this);