This article describes how to verify the validity of IP addresses and subnet masks in js. For more information, see
The Code is as follows:
Function checkIP)
{
Obj = ip;
Var exp =/^ (\ d {1, 2} | 1 \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ d {1, 2} | 1 \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ d {1, 2} | 1 \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ d {1, 2} | 1 \ d | 2 [0-4] \ d | 25 [0-5]) $ /;
Var reg = obj. match (exp );
If (reg = null)
{
Return false; // invalid
}
Else
{
Return true; // valid
}
}
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; // "invalid"
}
Else
{
Return true; // "valid"
}
}