isIPv4

import { isIPv4 } from "jsr:@ende/net/unstable-ip";

function ยท experimental

function isIPv4(addr: string): boolean

Validates whether a given string is a valid IPv4 address.

See parseIPv4 for the accepted syntax.

addr: string

IPv4 address in a string format (e.g., "192.168.0.1").

Returns

A boolean indicating if the string is a valid IPv4 address.

Example: Check if the address is a IPv4

import { isIPv4 } from "@ende/net/unstable-ip"
import { assert, assertFalse } from "@ende/assert"

const correctIp = "192.168.0.1"
const incorrectIp = "192.168.0.256"

assert(isIPv4(correctIp))
assertFalse(isIPv4(incorrectIp))

Source