Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki
Función para comprobar la validez de una dirección de correo electrónico - email - Delphi
Lenguaje de programación Borland Delphi


Os mostramos una función en Delphi para comprobar la validez de la sintaxis de una direción de correo electrónico (email):

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, shellapi;

type
  TformComprobarEmail = class(TForm)
    txtEmail: TEdit;
    lResultado: TLabel;
    bComprobar: TButton;
    Label2: TLabel;
    LWEB: TLabel;
    procedure bComprobarClick(Sender: TObject);
    procedure LWEBClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  formComprobarEmail: TformComprobarEmail;

implementation

{$R *.DFM}

function emailCorrecto (const email: string): Boolean;

  function comprobar (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;
  nombre, servidor : string;
begin
  Result := False;
  i := Pos('@', email);
  if i = 0 then
    Exit;
  nombre := Copy(email, 1, i-1);
  servidor := Copy(email, i + 1, Length(email));
  if (Length(nombre) = 0) or ((Length(servidor) < 5)) then
    Exit;
  i := Pos('.', servidor);
  if (i = 0) or (i > (Length(servidor) - 2)) then
    Exit;
  Result := comprobar (nombre) and comprobar (servidor);
end;

procedure TformComprobarEmail.bComprobarClick(Sender: TObject);
begin
  if emailCorrecto (txtEmail.Text) then
    lResultado.Caption := 'Correcto'
  else
    lResultado.Caption := 'Incorrecto';
end;

procedure TformComprobarEmail.LWEBClick(Sender: TObject);
begin
  ShellExecute(Handle, Nil, PChar(LWEB.CAPTION),
      Nil, Nil, SW_SHOWNORMAL);
end;

end.




Publicado el: 2006-03-05

Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A