js判断非127开头的IP地址

js验证回送地址,IP地址不能以127开头

回送地址(127.x.x.x)是本机回送地址(Loopback Address)

var ipNotStartWith127 = function(ip) {
    try {
        var data = ip.split("."), ip1;
        return 4 == data.length && 127 !== parseInt(data[0])
    } catch (e) {
        return !1
    }
}
console.log(ipNotStartWith127("127.0.0.1"));
// false
console.log(ipNotStartWith127("192.168.1.1"));
// true

猜你喜欢

转载自www.cnblogs.com/sirdong/p/12145496.html