Ir ao conteúdo
  • Cadastre-se

função valida email


camelo

Posts recomendados

Postado Originalmente por camelo@05 dez 2004, 00:32

To precisando de uma função, escrita em Delphi, pra validar email. Tambem serve função pra varrer uma String passando um index (não serve a função "pos", pois ela retorna o index do caracter encontrado). :unsure:

puxa cara... não sei programa em delphi, mas tenta fazer alguma coisa.. que verifique c tem @ (só pode ter 1) e c tem caracters antes ou depois... algo do genero!! beleza...

Link para o comentário
Compartilhar em outros sites

  • 2 semanas depois...
  • Membro VIP

Tente usar essa função:

    function WCMatchStrings( const Pattern, MatchString: String; 
                            CaseSensitive: Boolean ): Boolean;

           function DoWCMatch( Pattern: PChar; MatchString: PChar): Boolean;
           begin
             // have we run out of match string ?
             if ( MatchString^ = #0 ) then
               begin
                 // if we've run out of pattern as well, we've matched
                 if ( Pattern^ = #0 ) then
                   Result := True

                 // otherwise the only possibility for matching is that
                 // the remaining pattern consists of asterisks
                 else if ( Pattern^ <> '*' ) then
                   Result := False
                 else
                   Result := DoWCMatch( Pattern + 1, MatchString )
               end

             //otherwise there's some match string left
             else
               begin
                 // if we've run out of pattern, there's no match
                 if ( Pattern^ = #0 ) then
                   Result := False

                 // if we're at the final pattern character and it's an asterisk,
                 // there's an obvious match
                 else if ( ( Pattern + 1)^ = #0 ) and ( Pattern^ = '*' ) then
                   Result := True

                 // otherwise, try to match the current pattern character to
                 // the current match string character
                 else
                   begin
                     case Pattern^ of
                       '*': begin
                              Result := DoWCMatch( Pattern + 1, MatchString );

                              if not Result then
                                Result := DoWCMatch( Pattern, MatchString + 1 );
                            end;
                       '?': Result := DoWCMatch( Pattern + 1, MatchString );
                     else
                            if ( Pattern^ <> MatchString^ ) then
                              Result := False
                            else
                              Result := DoWCMatch( Pattern + 1,  MatchString + 1 );
                     end;
                   end;
               end;
           end;

   begin
     if CaseSensitive then
       Result := DoWCMatch( PChar( Pattern ), PChar( MatchString ) )
     else
       Result := DoWCMatch( PChar( UpperCase( Pattern ) ),
                            PChar( UpperCase( MatchString ) ) );
   end;

Ela faz busca com base em um padrão que você define e que pode incluir wildcards. Para um email, você pode definir um padrão (pattern) tipo *@*.com.br e também *@*.com

Link para o comentário
Compartilhar em outros sites

  • Membro VIP
Postado Originalmente por camelo@16 dez 2004, 02:36

beleza, mas passo como parametro o "@.com.br" e "@.com"??? B)

Use:

emailvalido:=WCMatchStrings('*@*.com.br', email, False);

emailvalido:=WCMatchStrings('*@*.com', email, False);

emailvalido:=WCMatchStrings('*@*', email, False);

Esse False é para ele ignorar se é letra maiúscula ou minúscula.

email seria o endereço que você tem. A última opção é apenas para olhar se tem @, que seria o ideal, pois nem todos os emails são se provedores .com . Como alguém disse, você deveria também usar uma função para contar quantos @ tem (deveria ter apenas um). Isso é fácil.

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...