<script language=javascript>
function check()
{
//alert("IP地址输入非法!");
var pattern=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
flag_ip=pattern.test(document.all.ip.value);
if(!flag_ip)
{
alert("IP地址输入非法!");
document.all.ip.focus();
return false;
}
}
</script>
<form onsubmit="return check()">
<INPUT TYPE="text" NAME="ip">
<INPUT TYPE="submit">
</form>
<script language=javascript>
function checkIP2()
{
var ip=document.all.ip.value;
var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
var reg = ip.match(exp);
var ErrMsg="你输入的是一个非法的IP地址段!\nIP段为::xxx.xxx.xxx.xxx(xxx为0-255)!"
var Msg="你输入的是一个合法的IP地址段!"
if(reg==null)
{
alert(ErrMsg);
}
else
{
alert(reg);
}
}
</script>
<form onsubmit="return checkIP2()">
<INPUT TYPE="text" NAME="ip">
<INPUT TYPE="submit">
</form>