啥都不用说了, 直接上菜:

<html>
<head>
</head>

<body>
<input id="xxx" οnblur="fun();" />

<script>
function isValidIP(ip)   
{   
    var reg =  /^(\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])$/   
    return reg.test(ip);   
}  


function fun()
{
	var ip = document.all.xxx.value;
	if(isValidIP(ip))
	{
		alert("yes");
	}
	else
	{
		alert("no");
	}
}

</script>

</body>

</html>



本文转载:CSDN博客