明辉手游网中心:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

全正则的检测IP是否合法的函数

[摘要]function checkIP2(sIPAddress) var exp=/^(\d1,2 1\d\d 2[0-4]\d 25[0-5])\.(\d1,2 1\d\d 2[0-4]\d 25[0-5])\.(\d1,2 1\d\d 2[0-4]\d 25[0-5])\.(\d1,2 1\d...

function checkIP2(sIPAddress)
{
    var exp=/^(\d{1,2} 1\d\d 2[0-4]\d 25[0-5])\.(\d{1,2} 1\d\d 2[0-4]\d 25[0-5])\.(\d{1,2} 1\d\d 2[0-4]\d 25[0-5])\.(\d{1,2} 1\d\d 2[0-4]\d 25[0-5])$/;
    var reg = sIPAddress.match(exp);
    var ErrMsg="你输入的是一个非法的IP地址段!\nIP段为::xxx.xxx.xxx.xxx(xxx为0-255)!"    
    var Msg="你输入的是一个合法的IP地址段!"    
    if(reg==null)
    {
        alert(ErrMsg);
    }
    else
    {
        alert(reg);
    }
}(出处:Viphot)