Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Go Back   Foros Club Delphi > Otros temas > Trucos
Register FAQ Members List Calendar Guía de estilo Today's Posts

Los mejores trucos

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02/07/2016
rretamar's Avatar
[rretamar] rretamar is offline
Miembro Premium
 
Join Date: Aug 2006
Location: San Francisco, Córdoba, Argentina
Posts: 1,168
Poder: 23
rretamar Va camino a la famarretamar Va camino a la fama
Validando una dirección de correo-e

Una función para comprobar una dirección de correo electrónico ingresada, de manera muy estricta. Funciones de este tipo hay varias, esta de la más completa que encontré. Leer código bien escrito es un placer, y Object Pascal lo hace más agradable aún.

Fuente: http://www.howtodothings.com/compute...in-delphi.html


Código Delphi [-]
Function ValidEmail(email: String): Boolean;
  // Returns True if the email address is valid
  // Author: Ernesto D'Spirito
Const
  // Valid characters in an "atom"
  atom_chars = [#33..#255] - ['(', ')', '<', '>', '@', ',', ';', ':',
    '\', '/', '"', '.', '[', ']', #127];
  // Valid characters in a "quoted-string"
  quoted_string_chars = [#0..#255] - ['"', #13, '\'];
  // Valid characters in a subdomain
  letters = ['A'..'Z', 'a'..'z'];
  letters_digits = ['0'..'9', 'A'..'Z', 'a'..'z'];
  subdomain_chars = ['-', '0'..'9', 'A'..'Z', 'a'..'z'];
Type
  States = (STATE_BEGIN, STATE_ATOM, STATE_QTEXT, STATE_QCHAR,
    STATE_QUOTE, STATE_LOCAL_PERIOD, STATE_EXPECTING_SUBDOMAIN,
    STATE_SUBDOMAIN, STATE_HYPHEN);
Var
  State: States;
  i, n, subdomains: Integer;
  c: Char;
Begin
  State := STATE_BEGIN;
  n := Length(email);
  i := 1;
  subdomains := 1;
  While (i <= n) Do
  Begin
    c := email[i];
    Case State Of
      STATE_BEGIN:
        If c In atom_chars Then
          State := STATE_ATOM
        Else If c = '"' Then
          State := STATE_QTEXT
        Else
          break;
      STATE_ATOM:
        If c = '@' Then
          State := STATE_EXPECTING_SUBDOMAIN
        Else If c = '.' Then
          State := STATE_LOCAL_PERIOD
        Else If Not (c In atom_chars) Then
          break;
      STATE_QTEXT:
        If c = '\' Then
          State := STATE_QCHAR
        Else If c = '"' Then
          State := STATE_QUOTE
        Else If Not (c In quoted_string_chars) Then
          break;
      STATE_QCHAR:
        State := STATE_QTEXT;
      STATE_QUOTE:
        If c = '@' Then
          State := STATE_EXPECTING_SUBDOMAIN
        Else If c = '.' Then
          State := STATE_LOCAL_PERIOD
        Else
          break;
      STATE_LOCAL_PERIOD:
        If c In atom_chars Then
          State := STATE_ATOM
        Else If c = '"' Then
          State := STATE_QTEXT
        Else
          break;
      STATE_EXPECTING_SUBDOMAIN:
        If c In letters Then
          State := STATE_SUBDOMAIN
        Else
          break;
      STATE_SUBDOMAIN:
        If c = '.' Then
        Begin
          Inc(subdomains);
          State := STATE_EXPECTING_SUBDOMAIN;
        End
        Else If c = '-' Then
          State := STATE_HYPHEN
        Else If Not (c In letters_digits) Then
          break;
      STATE_HYPHEN:
        If c In letters_digits Then
          State := STATE_SUBDOMAIN
        Else If c <> '-' Then
          break;
    End;
    Inc(i);
  End;
  If i <= n Then
    Result := False
  Else
    Result := (State = STATE_SUBDOMAIN) And (subdomains >= 2);
End;
__________________
Lazarus Codetyphon : Desarrollo de aplicaciones Object Pascal, libre y multiplataforma.
Reply With Quote
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: too much mail from (dirección ip) enviando correo masivo Gregorio Cíber Internet 2 10/07/2015 13:43
Como Saber si una Dirección de Correo es Válida???? AGAG4 Internet 30 19/07/2011 18:36
Pueden Ver Mi Direccion De Correo? CITHALI ACERMA Seguridad 12 18/06/2006 22:49
El correo que mando a una direccion de hotmail no llega bien URBANO Internet 1 27/04/2005 07:53
Ejecutar cliente de correo pasandole la direccion del destinatario Durbed API de Windows 1 19/10/2004 12:34


All times are GMT +2. The time now is 03:33.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi