Jump to content

HowTo: check for a valid e-mail syntax/address


mierlp

Recommended Posts

I use this function:

 

function ValidarEMail(vStr: string): Boolean;
begin
  vStr := Trim(UpperCase(vStr));
  if Pos('@', vStr) > 1 then
    begin
      Delete(vStr, 1, pos('@', vStr));
      Result := (Length(vStr) > 0) and (Pos('.', vStr) > 2);
    end
  else
    Result := False;
end;
Link to comment
Share on other sites

I use TRegEx

 
var
FoundMatch: Boolean;
 
FoundMatch := False;
try
     FoundMatch := TRegEx.IsMatch(S, '\A\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b\z', [roIgnoreCase]);
except
     on E: ERegularExpressionError do
     begin
            // Syntax error in the regular expression
     end;
end;
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...