Jump to content

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


mierlp

Recommended Posts

Hi

 

For creating a username in my application i use the customer e-mail address.

 

Is there a example how to check if the entered e-mail address has a valid syntax with @ and .

 

Regards Peter

Link to comment
Share on other sites

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...