js驗證回送地址,IP地址不能以127開頭oop
回送地址(127.x.x.x)是本機回送地址(Loopback Address)spa
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