Home >Web Front-end >JS Tutorial >js verification example of legality and validity of IP and subnet mask_javascript skills

js verification example of legality and validity of IP and subnet mask_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:50:471235browse
Copy code The code is as follows:

function checkIP(ip)
{
obj=ip ;
var exp=/^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4 ]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0 -4]d|25[0-5])$/;
var reg = obj.match(exp);
if(reg==null)
{
return false;// Illegal
}
else
{
return true; //Legal
}
}

function checkMask(mask)
{
obj =mask;
var exp=/^(254|252|248|240|224|192|128|0).0.0.0|255.(254|252|248|240|224|192|128| 0).0.0|255.255.(254|252|248|240|224|192|128|0).0|255.255.255.(254|252|248|240|224|192|128|0)$/ ;
var reg = obj.match(exp);
if(reg==null)
{
return false; //"illegal"
}
else
{
return true; //"Legal"
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn