Re: How to test of e-mail address is valid

Giganews Newsgroups
Subject: Re: How to test of e-mail address is valid
Posted by:  loki (loki5100-newsgro…@yahoo.fr)
Date: Mon, 9 May 2005

It's a function in my component suite (Alcinoe)

function AlIsValidEmail(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
  Result:= false;
  i:= AlCharPos('@', Value);
  if (i = 0) or (ALpos('..', 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:= AlCharPos('.', serverPart);
  // must have dot and at least 2 places from end
  if (i = 0) or (i > (Length(serverPart) - 2)) then Exit;
  Result:= CheckAllowed(namePart) and CheckAllowed(serverPart);
end;

kind regards
stéphane

"Nols Smit" <nols_sm…@yahoo.com> wrote in message
news:D061BE6423CAE240nols_sm…@yahoo.com...
>I use the TidSMTP.QuickSend command in an IntraWeb application to send
> email.  How do I test if the e-mail address is valid before I send the
> mail?
>
> Regards,
>
> Nols Smit

Replies

None

In response to

How to test of e-mail address is valid posted by Nols Smit on Mon, 9 May 2005