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

WBOY
Release: 2016-05-16 16:50:47
Original
1191 people have browsed it
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"
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template