whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

27 Visitors Online


 
...check if a String is a valid IP Address (II)?
Autor: Opa
[ Print tip ]  

Tip Rating (23):  
     


// Die Lösung
// http://www.swissdelphicenter.ch/de/showcode.php?id=381
// ist leider nicht richtig!

// Einen String auf eine gültige IP-Adresse überprüfen wenn das Format
// '000.000.000.000 bzw. 0.0.0.0 ist / sein sollte.

function IsWrongIP(Ip: string): Boolean;
const
  
Z = ['0'..'9', '.'];
var
  
I, J, P: Integer;
  W: string;
begin
  
Result := False;
  if (Length(Ip) > 15) or (Ip[1] = '.') then Exit;
  I := 1; 
  J := 0; 
  P := 0; 
  W := '';
  repeat
    if 
(Ip[I] in Z) and (J < 4) then
    begin
      if 
Ip[I] = '.' then
      begin
        
Inc(P);
        J := 0;
        try
          
StrToInt(Ip[I + 1]);
        except
          
Exit;
        end;
        W := '';
      end 
      else 
      begin
        
W := W + Ip[I];
        if (StrToInt(W) > 255) or (Length(W) > 3) then Exit;
        Inc(J);
      end;
    end
    else 
      
Exit;
    Inc(I);
  until I > Length(Ip);
  if P < 3 then Exit;
  Result := True;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners