IsValidIP ?

Giganews Newsgroups
Subject: IsValidIP ?
Posted by:  us…@domain.invalid
Date: Fri, 16 Oct 2009

IsValidIP('1.2.2.3.localhost')

function IsValidIP(const S: String): Boolean;
var
  j, i: Integer;
  LTmp: String;
begin
  Result := False;
  LTmp := Trim(S);
  for i := 1 to 4 do begin
    j := IndyStrToInt(Fetch(LTmp, '.'), -1);    {Do not Localize}
    if (j < 0) or (j >= 256) then begin
      Exit;
    end;
+    if ((i = 4) and (LTmp <> '')) then Exit;
  end;
  Result := True;
end;

Replies