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 nativexml的中文支持

Delphi unigui获取连接的客户端列表

Delphi 程序窗体及控件自适应分辨率

Delphi link() 精简打开网址

Delphi中使用词霸2005的动态库xdictgrb.dll实现屏幕取词

Delphi drawing text 绘制文本

Delphi强制应用非一次性载入的注册表设置

Delphi文件 fileopen 、fileseek等的用法(看红色字体)

Delphi 全盘搜索指定文件

Delphi tdirectory.tfilterpredicate

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



打赏

取消

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

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

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

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

评论

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