isIP

Checks whether a string has an IP address format (both IPv4 and IPv6)

bool
isIP
(
string ip
)

Parameters

ip string

the IP address to do check on

Examples

assert(isIP("192.169.0.0"));
assert(isIP("2001:db8:0:1:1:1:1:1"));
assert(!isIP("192.169.0.500"));
assert(!isIP("2001:db8:0:1:1:1:1:1xxx"));

Meta