« 批量设置 IP 的 shell 代码 | Main | 解压 .tar .tar.gz 文件中的个别文件的方法 »
October 13, 2006
判断 IP 的 javascript 代码
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。 https://windtear.net/archives/2006/10/13/001111.html http://windtear.net/archives/2006/10/13/001111.html 判断 IP 的 javascript 代码 function n(x) { return ( (!isNaN(x)) && x<=255 && x>=0); } function checkip(myform) { var ip=myform.q.value.split("."); if(ip[3]=="*" || ip[3]=="?") { ip[3]=1; myform.q.value=ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]; } if( ! ((ip.length==4)?(n(ip[0])&&n(ip[1])&&n(ip[2])&&n(ip[3])):false) ) { alert("IP 地址有误\n请重新输入!\n\n正确的格式举例: \n 166.111.1.1"); myform.q.select(); myform.q.focus(); return false; } } <form method="post" onSubmit="return checkip(this);"> onClick="JavaScript:this.select()" |
Posted by windtear at October 13, 2006 11:53 PM