<script>
ip= "192.157.4.4 "
re=/(d+).(d+).(d+).(d+)/g //匹配ip地址的正则表达式
alert(re.test(ip))
</script>
<script>
ip= "555.255.284.255 "
re=/^(([3-9]d?|[01]d{0,2}|2d?|2[0-4]d|25[0-5]).){3}([3-9]d?|[01]d{0,2}|2d?|2[0-4]d|25[0-5])/
alert(re.test(ip))
</script>
<script>
var ip= "61.255.204.259 ";
if(ip.match(/(d+).(d+).(d+).(d+)/g))
alert( "error ip address format. ");
var parts=ip.split( ". ");
for(var i=0,l=parts.length;i <l;i++){
if(parseint(parts[i],10)> 255){
alert( "error ip address format. ");
break;
}
}
时间: 2024-11-27 17:39:08