function checkIp(ip){
var ipPattern = new RegExp(
"^(([1-9][0-9]?)|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\\.
((0)|([1-9][0-9]?)|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\\.
((0)|([1-9][0-9]?)|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\\.
((0)|([1-9][0-9]?)|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))$","g");
var ip6Pattern=new RegExp(
"^(^::$)
|(^([\\d|a-fA-F]{1,4}:){7}([\\d|a-fA-F]{1,4})$)
|(^(::(([\\d|a-fA-F]{1,4}):){0,5}([\\d|a-fA-F]{1,4}))$)
|(^(([\\d|a-fA-F]{1,4})(:|::)){0,6}([\\d|a-fA-F]{1,4})$)$","g");
if(ipPattern.test(ip)){
return true;
}
if (ip6Pattern.test(ip)){
var pos=ip.indexOf("::");
if (pos>-1)
{
pos=ip.indexOf("::",pos+2);
if (pos>-1) return false;
}
return true;
}
return false;
}
阅读(3567) | 评论(0) | 转发(0) |