Skip to content

isNetworkValid()

Evgheniy Kovaliov edited this page Dec 22, 2023 · 1 revision

isNetworkValid(network)

Description

Method that allows you to check the correctness of the ip network.
Correct ip network address must be a string in X.X.X.X/PREF format, where X.X.X.X is a correct ip address, and PREF is a correct ip prefix.
Also 'host part' (that determined by ip prefix) of address must be filled by zeros.

Contract

Parameters:

  • network — value, that will be checked.

Return:

  • true/false
Usage
ipv4.isNetworkValid('0.0.0.0/0')          // true
ipv4.isNetworkValid('255.255.255.255/32') // true
ipv4.isNetworkValid('0.0.0.0/32')         // true
ipv4.isNetworkValid('123.122.120.0/22')   // true
ipv4.isNetworkValid('10.0.0.0/31')        // true

ipv4.isNetworkValid('10.0.0.1/31')        // false
ipv4.isNetworkValid('123.122.120.0/20')   // false
ipv4.isNetworkValid('125.12.28.64/24')    // false
ipv4.isNetworkValid('123.123.10.1')       // false
ipv4.isNetworkValid(['0.0.0.0', '/0'])    // false
  • Is used in other methods.

MAIN PAGE

See all methods documentation:

For ip version 4

For ip version 6

Clone this wiki locally