function CheckMAC(const MacAddress: string): Boolean;
var
i : integer;
begin
Result := False;
{i - fixed length}
if ( Length(MacAddress) <> Length('ab:cd:ef:ab:cd:ef') ) then
exit;
{ii - check for hex format in all elements }
for i := 0 to 5 do
if (-1 = (StrToIntDef(HexDisplayPrefix + Copy(MacAddress, i* 3 + 1, 2), -1))) then
Exit;
Result := True;
end;
function CheckIP(const IpAddress: string): Boolean;
var
SL: TStringList;
i : integer;
octet : integer;
begin
Result := False;
SL := TStringList.Create;
try
SL.Delimiter := '.';
SL.DelimitedText := IpAddress;
{i - must be 4 octets}
if (SL.Count <> 4) then
Exit;
{ii - must be a byte }
for i := 0 to 3 do
begin
octet := StrToIntDef(SL[i], -1);
if (octet < 0) or (octet > 255) then
Exit;
end;
Result := True;
finally
SL.Free;
end;
end;
function CheckPort(const Port: string): Boolean;
var
nPort: Integer;
begin
Result := True;
nPort := StrToIntDef(Port, -1);
if (nPort < Low(Word)) or (nPort > High(Word)) then
Result := False;
end;
增加:
function isValidPort(Port: String): Boolean;
begin
if IsNumeric(Port) = True then
begin
if (StrToInt(Port) >= 0) and (StrToInt(Port)<= 65535) then
isValidPort := True
else
isValidPort := False;
end
else
isValidPort := False;
end;
function isValidMac(MacAddress: String): Boolean;
begin
MacAddress := StringReplace(MacAddress, '-', '', [rfReplaceAll]);
MacAddress := StringReplace(MacAddress, ':', '', [rfReplaceAll]);
if Length(MacAddress) = 12 then
isValidMac := IsHexidecimal(MacAddress)
else
isValidMac := False;
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.033937931060791 seconds