For the old version of Delphi that doesn't have Regular expression :
function TForm1.IsValidEmail(email: string): boolean;
const
charslist = ['_', '-', '.', '0'..'9', 'A'..'Z', 'a'..'z'];
var
Arobasc, lastpoint : boolean;
i, n : integer;
c : char;
begin
n := Length(email);
i := 1;
Arobasc := false;
lastpoint := false;
result := true;
while (i <= n) do begin
c := email[i];
if c = '@' then
begin
if Arobasc then // Only 1 Arobasc
begin
result := false;
exit;
end;
Arobasc := true;
end
else if (c = '.') and Arobasc then // at least 1 . after arobasc
begin
lastpoint := true;
end
else if not(c in charslist) then // valid chars
begin
result := false;
exit;
end;
inc(i);
end;
if not(lastpoint) or (email[n] = '.')then // not finish by . and have a . after arobasc
result := false;
end;
For the one who like to use RegExpression using Database server
function TForm1.IsValidEmail(const AMail: string): Boolean;
var
lQry: TSQLQuery;
begin
// no REGEXP in Delphi 2009 -> use of REGEPX Oracle
lQry := TSQLQuery.Create();
lQry.SQLConnection := SQLConnection1;
try
vQry.SQL.Text := 'SELECT REGEXP_SUBSTR( ' + QuotedStr(aMail) + ', ''^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{1,}$'' ) "EMAIL" FROM DUAL'; // ORACLE
// vQry.SQL.Text := 'SELECT ' + QuotedStr(aMail) + ' REGEXP ''^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9.-]@[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]\.[a-zA-Z]{2,4}$''; // MySQL
lQry.Open;
Result := not lQry.Eof and ( lQry.FieldByName( 'EMAIL' ).AsString = AMail );
finally
FreeAndNil(lQry);
end;
end;