Skip to content

isMaskValid()

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

isMaskValid(mask)

Description

Method that allows you to check the correctness of the ip subnet mask.
Correct ip subnet mask must be a string in format: X.X.X.X, where X is a number from 0 to 255.
And in binary form of ip subnet mask zeros can only be after all ones. For example: 11111111.11111111.11100000.00000000.

Contract

Parameters:

  • mask — value, that will be checked.

Return:

  • true/false
Usage
ipv4.isMaskValid('0.0.0.0');         // true
ipv4.isMaskValid('255.255.255.255'); // true
ipv4.isMaskValid('255.255.0.0');     // true
ipv4.isMaskValid('128.0.0.0');       // true
ipv4.isMaskValid('255.240.0.0');     // true
ipv4.isMaskValid('255.255.255.254'); // true
ipv4.isMaskValid('255.255.255.252'); // true

ipv4.isMaskValid('255.255.255.253'); // false
ipv4.isMaskValid('111.1.0.0');       // false
ipv4.isMaskValid('128.0.0.1');       // false
ipv4.isMaskValid('128.128.128.128'); // false
ipv4.isMaskValid('string...');       // false
  • Is used in other methods.

MAIN PAGE

See all methods documentation:

For ip version 4

For ip version 6

Clone this wiki locally