求一个函数,判断输入的字符串是否是合法IP
解决方案 »
- 关于图像处理的(跪求犀利哥降临~!)
- 为火箭骄傲!
- dephi的tinifile类的疑问?
- 怎么让Delphi7开发出越南语的软件?
- 好东西大家共享,!!<<十面埋伏>>BT下载地址
- 如何指定TQuery访问数据库的路径。
- 朋友们都进来看看,提点见
- 谁能给一个java(client)和delphi(server)通信的example,马上给分!!
- select price+0.5 as newprice from shop,为什么dbgrid中反映的字段名不是newprice而是Expr1014
- 在Treeview中建立节点
- 在控制台程序中如何得到程序的句柄
- 如果让一个biBitCount=8的位图与一个DC兼容!
var
iCount:Integer;
iIPLength:Integer;
iFieldLength:Integer;
iFieldStart:Integer;
iDotCount:Integer;
strTemp:String;
begin
iIPLength:=Length(astrIP);
if (iIPLength>15)or(iIPLength<7)then
begin
Result:=False;//合法IPv4长度在7和15之间
Exit;
end; iDotCount:=0;
iFieldLength:=0;
iFieldStart:=1;
for iCount:=1 to iIPLength do
begin
case astrIP[iCount] of
"0","1","2","3","4","5","6","7","8","9":
begin
iFieldLength:=iFieldLength+1;
if (3<iFieldLength) then
begin
Result:=False;//IP的单域长度超过3
Exit;
end;
end;
"."
begin
if 0=iFieldLength then
begin
Result:=False;//"."在开头或连续两个".",或在结尾
Exit;
end;
strTemp:=copy(astrIp,iFieldStart,iCount-iFieldStart);
if(255<StrToInt(strTemp))then
begin
Result:=False;//单域值>255
Exit;
end;
iDotCount:=iDotCount+1;
if 3<iDotCount then
begin
Result:=False;//超过4个域
Exit;
end;
iFieldLength:=0;
iFieldStart:=iCount+1;
end;
else
begin
Result:=False;//非法字符
Exit;
end;
end; Result:=True;
end;
IdStack;
GStack.IsIP(StrIP)