关于种判断ip地址的输入有效性的哪种函数?

memgarden 2002-03-20 11:22:51
给位,有没有做过那种判断ip地址的输入有效性的哪种函数,asp中用的,请各位大虾指教,急着用的,如果有源代码,请贴出!!!谢谢了
...全文
109 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
8988 2002-03-20
  • 打赏
  • 举报
回复
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>
memgarden 2002-03-20
  • 打赏
  • 举报
回复
如果要进一步判断比较ip地址的大小怎么写,如果第二个ip地址>=第一个ip地址,为true,否则,为false
memgarden 2002-03-20
  • 打赏
  • 举报
回复
beyond_xiruo(希偌) ,你写的好像有点问题,你只判别是不是0-9数字和点的格式和位置,并没有判断,这个数是不是在0-255之间。
flyukeer 2002-03-20
  • 打赏
  • 举报
回复
自己写一个
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
karma 2002-03-20
  • 打赏
  • 举报
回复
try


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;
}

if (i > 4)
alert("good");
else
alert("bad!");

}
else
alert("bad");
希偌 2002-03-20
  • 打赏
  • 举报
回复
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;
}
memgarden 2002-03-20
  • 打赏
  • 举报
回复
wait.....
julyclyde 2002-03-20
  • 打赏
  • 举报
回复
IP地址没有大小比较这一说吧?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧