Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

How to varify a email address

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public procedure ValidEmail(sEmail:string); { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin ValidEmail(Edit1.text); end; procedure TForm1.ValidEmail(sEmail: string); var at,dot,i:Integer; bOkay:boolean; sline:string; begin at:=Pos('@',sEmail); dot :=LastDelimiter('.',sEmail); bOkay:=(at>0)and(dot>at); if bOkay then begin for i:=1 to Length(sEmail) do begin if not (sEmail[i] in ['a'..'z','A'..'Z','0'..'9','-','_','.','@']) then begin bOkay:=false; break; end; end end; if not bOkay then Showmessage('Not a valid Email address') else ShowMessage('Valid Address'); end; end.