Source Code



Check or Validate e-mail address

  • anonymous
  • Dec 14' 13
  • Delphi
  • 290
  • 79
  • United States

Use function IsValidEmail, if you want to check any e-mail address. This function checks syntax of each part of e-mail address.

function IsValidEmail(const Value: string): Boolean;

  function CheckAllowed(const s: string): Boolean;
  var i: Integer;
  begin
    Result:= false;
    for i:= 1 to Length(s) do
      if not (s[i] in ["a".."z", 
                       "A".."Z", 
                       "0".."9", 
                       "_", 
                       "-", 
                       "."]) then Exit;
    Result:= true;
  end;

var
  i: Integer;
  NamePart, ServerPart: string;
begin
  Result:= False;
  i:=Pos("@", Value);
  if i=0 then Exit;
  NamePart:=Copy(Value, 1, i-1);
  ServerPart:=Copy(Value, i+1, Length(Value));
  if (Length(NamePart)=0) or ((Length(ServerPart)&lt5)) then Exit;
  i:=Pos(".", ServerPart);
  if (i=0) or (i&gt(Length(serverPart)-2)) then Exit;
  Result:= CheckAllowed(NamePart) and CheckAllowed(ServerPart);
end;
  • Tags : validate, email, windows
comments powered by Disqus

Related Code

Disable/enable taskbar

Extracting Email Addresses



Category