1、在服务器端判断
<%
ip="234.567.234.33"
ips=split(ip,".")
if UBound(ips)<>4 then
response.write "IP必须4位"
response.end
else
for i=0 to 3
if cint(ips(i))<0 or cint(ips(i))>255 then
response.write "IP每位必须是0—255之间的数"
response.end
end if
next
end if
response.write "你的IP是:" & IP
response.end
%>
2、在客户端判断
<script>
ip="a234.567.234.33";
isIP(ip);
function isIP(ip){
ips=ip.split(/\./g);
if (ips.length!=4) {alert("IP必须4位.");return;}
for (i=0;i<4;i++){
ipn=parseInt(ips[i]);
if (isNaN(ipn) || ipn<0 || ipn>255) {alert("IP每位必须是0—255之间的数.");return;}
alert(ipn);
}
}
</script>
自己写一个
function ipcheck(ip)
dim temp
temp=left(ip,instr(ip,".")-1)
ip=right(ip,len(ip)-instr(ip,"."))
if cint(temp)>255 and cint(temp)<0 and temp<>"" then
ipcheck=false
exit function
end if
temp=left(ip,instr(ip,".")-1)
ip=right(ip,len(ip)-instr(ip,"."))
if cint(temp)>255 and cint(temp)<0 and temp<>"" then
ipcheck=false
exit function
end if
temp=left(ip,instr(ip,".")-1)
ip=right(ip,len(ip)-instr(ip,"."))
if cint(temp)>255 and cint(temp)<0 and temp<>"" then
ipcheck=false
exit function
end if
if cint(ip)>255 and cint(ip)<0 and ip<>"" then
ipcheck=false
exit function
end if
ipcheck=true
end function
var ip = "127.0.0.1";
var re = new RegExp("^([0-9]+).([0-9]+).([0-9]+).([0-9]+)$");
if (re.test(ip))
{
var i;
for (i=1; i <=4 ;i++)
{
var n = eval("RegExp.$"+i);
alert(n);
if (n < 0 || n > 255)
break;
}
var regu = "^([0-9]).([0-9]).([0-9]).([0-9])$"
var re = new RegExp(regu);
if (theForm.mail.value.search(re) != -1)
{
return true;
}
else
{
window.alert ("ip err!")
return false;
}