cidr-block - v2.1.1
    Preparing search index...

    Function isValidAddress

    • Validates whether the given input is a valid IPv4 address.

      Parameters

      • ip: Ipv4AddressLiteral

        The IPv4 address to validate, which can be in string, number, or octet array format.

      Returns boolean

      True if the input is a valid IPv4 address; otherwise, false.

      import { ipv4 } from 'cidr-block';

      ipv4.isValidAddress("192.168.1.1"); // true
      ipv4.isValidAddress("256.0.0.1"); // false (octet out of range)
      ipv4.isValidAddress(3232235777); // true
      ipv4.isValidAddress([192, 168, 1, 1]); // true
      ipv4.isValidAddress("invalid"); // false