<SCRIPT language=JavaScript>
<!--
function checkIP()
{
var ipArray,ip,j;
ip = document.form1.ip.value;
if(/[^\d\.]/.test(ip))
{
alert("请输入正确的IP!");
document.form1.ip.focus();
return false;
}
ipArray = ip.split(".");
j = ipArray.length
if(j!=4)
{
alert("请输入正确的IP!");
document.form1.ip.focus();
return false;
}
for(var i=0;i<4;i++)
{
if(ipArray[i].length==0 || ipArray[i]>255)
{
alert("请输入正确的IP!");
document.form1.ip.focus();
return false;
}
}
}
//-->
</SCRIPT>
回车键提交
<form name="form1" method="post" action="" onsubmit="return checkIP();">
<input type="text" name="ip" value="">
</form>