Delph i判断IP地址是否正确


本文整理自网络,侵删。

 function IsValidIP(strIP: string): Boolean;
var
  i, PartCount {用多少段,以点号分开}: Integer;
  Part: string;
begin
  PartCount := 0;
  while strIP <> '' do
  begin
    i := Pos('.', strIP);
    if i = 0 then
    begin
      Part := strIP;
      strIP := '';
    end
    else
    begin
      Part := Copy(strIP, 1, i - 1);
      Delete(strIP, 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获取其他进程中listbox和combobox的内容

Delphi 基础学习 字符串去掉回车符

Delphi webbrowser用记事本查看源代码

Delphi单元文件基本结构

Delphi 关于汉字换行问题

Delphi之memo组件

Delphi使用迅雷的开放下载引擎下载

Delphi 自带gif控件的动画图片加载和播放

Delphi 将dbgrid的数据导出到excel文件保存

Delphi 10.3 中安装程序自动升级插件autoupgrader_pro_v5.2

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



打赏

取消

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

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

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

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

评论

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