Delphi Email格式验证

来源:百度知道 编辑:UC知道 时间:2024/06/04 03:42:32
在文本框中输入一行字符,判断这行字符是否是Email格式的.

function EMailAddCheck(EmailAdd:string;var Errorcode:string):Boolean;
function CheckAt(s :string):integer;
var
num,t :integer;
begin
num := 0;
t := pos('@',s);
while t <> 0 do
begin
inc(num);
s := copy(s,t+1,length(s)-t);
t := pos('@',s);
end;
result := num;
end;
var
i,j :integer;
str :string;
begin
i := pos('@',EmailAdd);
str := Copy(EmailAdd,i+1,length(EmailAdd)-i);
j := pos('.',str);
result := false;
if i = 0 then
ErrorCode := '地址串中缺少"@"'
else if i = 1 then
ErrorCode := '第一位是"@",即缺少用户名'
else if i = Length(EmailAdd) then
ErrorCode := '最后一位是"@",即缺少服务器名'
else if j = 0 then
ErrorCode := '服务器名中缺少"."'
else if (j = 1) or (j = length(str