我想在正则表达式中检查 ip 地址的范围,我正在使用这种方式,它工作得非常成功
function validate_ip(ip)
{
// See if x looks like an IP address using our "almost IP regex".
var regex = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var match = regex.exec(ip);
if (!match) return false;
// Additional code to check that the octets aren't greater than 255:
for (var i = 1; i <= 4; ++i) {
if (parseInt(match[i]) > 255)
return false;
}
return true;
}
现在我想在正则表达式中检查范围和语法可以这样做吗?