Delphi判断IP地址是否正确


本文整理自网络,侵删。

  
function IsValidIP(Str: string): Boolean;
var
i, PartCount {用多少段,以点号分开}: Integer;
Part: string;
begin
PartCount := 0;
while Str <> '' do
begin
    i := Pos('.', Str);
    if i = 0 then
    begin
      Part := Str;
      Str := '';
    end
    else
    begin
      Part := Copy(Str, 1, i - 1);
      Delete(Str, 1, i);
    end;

    //IP分段必须是[0,255]的整数
    if not TryStrToInt(Part, i) or (i < 0) or (i > 255) then
    begin
      Result := False;
      Exit;
    end;
    Inc(PartCount);
end;

Result := PartCount = 4; //必须要有4段
end;

相关阅读 >>

Delphi 系统任务栏 窗口状态显示进度

Delphi 获取/设置桌面窗口样式的Delphi代码

Delphi 文件查找findfirst,findnext,findclose

Delphi 的内存操作函数(5): 复制内存

Delphi xe5 android 获取网络状态

Delphi 判断字符串是否是单词

Delphi 的内存操作函数(4): 清空与填充内存

Delphi 如何删除动态数组的指定元素

Delphi 一个定时器timer1相关的简单例子

Delphi图像处理 -- 图像卷积

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...