Skip to content

Utils / Full Stack / isValidIP

Function: isValidIP()

ts
function isValidIP(ip, options?): boolean;

Validates if the given string is a valid IP address.

Supports IPv4, IPv6, or both depending on the version option.

Parameters

ParameterTypeDescription

ip

string

The string to validate as an IP address.

options

{ version?: 4 | 6; }

Validation options.

options.version?

4 | 6

If specified, restricts validation to 4 (IPv4 only) or 6 (IPv6 only). Defaults to both.

Returns

boolean

true if the string is a valid IP address, otherwise false.

Example

typescript
isValidIP("192.168.1.1"); // true
isValidIP("192.168.1.1", { version: 4 }); // true
isValidIP("192.168.1.1", { version: 6 }); // false
isValidIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // true
isValidIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334", { version: 6 }); // true
isValidIP("localhost"); // false

Version v1.33.1 - Built on 2026-03-28