Skip to content

Utils / Full Stack / isValidIPv4

Function: isValidIPv4()

ts
function isValidIPv4(ip): boolean;

Parameters

ParameterTypeDescription

ip

string

The string to validate as an IPv4 address.

Returns

boolean

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

Deprecated

Use isValidIP(ip, { version: 4 }) instead. This function will be removed in a future major version.

See

isValidIP

(Deprecated) Validates if the given string is a valid IPv4 address.

An IPv4 address consists of four octets separated by dots, where each octet is a number between 0 and 255.

Example

typescript
// Prefer the new way:
isValidIP("192.168.1.1", { version: 4 }); // true
// Legacy:
isValidIPv4("192.168.1.1"); // true
isValidIPv4("256.256.256.256"); // false
isValidIPv4("localhost"); // false

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