检查email是否合法。
function IsValidEmail(const Value: string): boolean;
function CheckAllowed(const s: string): boolean;
var
i: integer;
begin
Result:= false;
for i:= 1 to Length(s) do
begin
// illegal char in s -> no valid address
if not (s[i] in ['a'..'z','A'..'Z','0'..'9','_','-','.']) then
Exit;
end;
Result:= true;
end;
var
i: integer;
namePart, serverPart: string;
begin // of IsValidEmail
Result:= false;
i:= Pos('@', Value);
if (i = 0) or (pos('..', Value) > 0) then
Exit;
namePart:= Copy(Value, 1, i - 1);
serverPart:= Copy(Value, i + 1, Length(Value));
if (Length(namePart) = 0) // @ or name missing
or ((Length(serverPart) < 4)) // name or server missing or
then Exit; // too short
i:= Pos('.', serverPart);
// must have dot and at least 3 places from end
if (i = 0) or (i >= (Length(serverPart) - 2)) then
Exit;
Result:= CheckAllowed(namePart) and CheckAllowed(serverPart);
end;
调用例子:
var
EmailName: string;
begin
EmailName := InputBox('输入你的E-Mail', 'E-Mail:', '');
if IsValidEmail(EmailName) then showmessage('Good!')
else showmessage('Worse');
end;
internet地址判断,ip地址搜索一下又讨论。其实你可以自己写判断 dot位置问题。搜索一下,“判断字符串是否为数字"。
function IsValidEmail(const Value: string): boolean;
function CheckAllowed(const s: string): boolean;
var
i: integer;
begin
Result:= false;
for i:= 1 to Length(s) do
begin
// illegal char in s -> no valid address
if not (s[i] in ['a'..'z','A'..'Z','0'..'9','_','-','.']) then
Exit;
end;
Result:= true;
end;
var
i: integer;
namePart, serverPart: string;
begin // of IsValidEmail
Result:= false;
i:= Pos('@', Value);
if (i = 0) or (pos('..', Value) > 0) then
Exit;
namePart:= Copy(Value, 1, i - 1);
serverPart:= Copy(Value, i + 1, Length(Value));
if (Length(namePart) = 0) // @ or name missing
or ((Length(serverPart) < 4)) // name or server missing or
then Exit; // too short
i:= Pos('.', serverPart);
// must have dot and at least 3 places from end
if (i = 0) or (i >= (Length(serverPart) - 2)) then
Exit;
Result:= CheckAllowed(namePart) and CheckAllowed(serverPart);
end;
调用例子:
var
EmailName: string;
begin
EmailName := InputBox('输入你的E-Mail', 'E-Mail:', '');
if IsValidEmail(EmailName) then showmessage('Good!')
else showmessage('Worse');
end;
internet地址判断,ip地址搜索一下又讨论。其实你可以自己写判断 dot位置问题。搜索一下,“判断字符串是否为数字"。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货