明輝手游網(wǎng)中心:是一個免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

全正則的檢測IP是否合法的函數(shù)

[摘要]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)