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
Validar una dirección de E-Mail - Delphi
Lenguaje de programación Borland Delphi


Para validar un dirección de correo electrónico (E-Mail), podemos utilizar esta función:

FUNCTION emailValido(CONST Value: String): boolean; 
  FUNCTION CheckAllowed(CONST s: String): boolean; 
  VAR i: Integer; 
  BEGIN 
  Result:= False; 
  FOR i:= 1 TO Length(s) DO // illegal char in s -> no valid address 
  IF NOT (s[i] IN ['a'..'z','A'..'Z','0'..'9','_','-','.']) THEN Exit; 
  Result:= true; 
  END; 
VAR 
  i,len: Integer; 
  namePart, serverPart: String; 
BEGIN // of IsValidEmail 
  Result:= False; 
  i:= Pos('@', Value); 
  IF (i=0) OR (Pos('..',Value) > 0) THEN Exit; 
  namePart:= Copy(Value, 1, i - 1); 
  serverPart:= Copy(Value,i+1,Length(Value)); 
  len:=Length(serverPart); 
  // must have dot and at least 3 places from end, 2 places from begin 
  IF (len<4) OR 
     (Pos('.',serverPart)=0) OR 
     (serverPart[1]='.') OR 
     (serverPart[len]='.') OR 
     (serverPart[len-1]='.') THEN Exit; 
  Result:= CheckAllowed(namePart) AND CheckAllowed(serverPart); 
END; 
Para utilizarla basta con:
  if emailValido ('ajpdsoft@ajpdsoft.com') then
    showmessage('El E-Mail es correcto')
  else
    showmessage('El E-Mail NO es correcto');




Publicado el: 2003-09-17

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