Created
June 8, 2018 13:05
-
-
Save anandpathak/c04053baff5d0cda1f43b9d8cb2c16c0 to your computer and use it in GitHub Desktop.
validate subnet mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _isValidsubnet= function(mask){ | |
if(/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/.test(mask) && mask !== "255.255.255.255"){ | |
var _mask = mask.split("."); | |
var str = _mask.map((val)=>{ return parseInt(val).toString(2)}).join(""); | |
console.log(str); | |
return ! (/01/.test(str)) | |
} | |
else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hope to test later today.