| 
      ...check if a String is a valid IP Address (II)?
     | 
   
   
    | Autor: 
      Opa     | 
   
  | [ Print tip 
] |   |   |   
 
 
 
// 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; 
 
 
 
  
                       |