Jump to content
Fórum Script Brasil
  • 0

Validação De Ip


thata

Question

1 answer to this question

Recommended Posts

  • 0

Ai vai:

function TForm1.IsWrongIP(ip: string): Boolean;
var
   z:integer;
   i: byte;
   st: array[1..3] of byte;
const
   ziff = ['0'..'9'];
begin
   st[1] := 0;
   st[2] := 0;
   st[3] := 0;
   z := 0;
   Result := False;
   for i := 1 to Length(ip) do if ip[i] in ziff then
   else begin
      if ip[i] = '.' then begin
         Inc(z);
         if z < 4 then st[z] := i
         else begin
            IsWrongIP := True;
            Exit;
         end;
      end else begin
         IsWrongIP := True;
         Exit;
      end;
   end;
   if (z <> 3) or (st[1] < 2) or (st[3] = Length(ip)) or
      (st[1] + 2 > st[2]) or (st[2] + 2 > st[3]) or
      (st[1] > 4) or (st[2] > st[1] + 4) or (st[3] > st[2] + 4) then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, 1, st[1] - 1));
   if (z > 255) or (ip[1] = '0') then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, st[1] + 1, st[2] - st[1] - 1));
   if (z > 255) or ((z <> 0) and (ip[st[1] + 1] = '0')) then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, st[2] + 1, st[3] - st[2] - 1));
   if (z > 255) or ((z <> 0) and (ip[st[2] + 1] = '0')) then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, st[3] + 1, Length(ip) - st[3]));
   if (z > 255) or ((z <> 0) and (ip[st[3] + 1] = '0')) then begin
      IsWrongIP := True;
      Exit;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 IsWrongIP(Edit1.text);
end;

ate+ wink.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...