Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/07/2004, 00:14
Avatar de dayala_ec
dayala_ec
 
Fecha de Ingreso: febrero-2001
Ubicación: En mi departamento propio en una zona tranquila dee Quito Ecuador
Mensajes: 9
Antigüedad: 24 años, 3 meses
Puntos: 0
Optimizar esta validación de campo Email en ASP

Hola amigos, buscaba una validación en ASP de un campo de formulario Email que valide correctamente el formato [email protected] e hice la función que muestro abajo que funciona bien pero es la una de la mañana y no he dormido en las últimas 72 horas, por favor ¿alguien puede revisar y decirme si he olvidado algo o se puede optimizar esta función?

Código:
function validarEmail(chr_Email)
   dim strCounter, strCounter2, ok
   strCounter=0
   strCounter2=0
   chr_Email = lCase(chr_Email)
   if len(Chr_Email)>80 or len(Chr_Email)<6 then
      Ok = FALSE
   else
      dim checkOK
      checkOK = "abcdefghijklmnopqrstuvwxyz0123456789-_.@"
      for i=1 to len(Chr_Email)
         for j=1 to len(checkOK)
            if mid(Chr_Email,i,1) = mid(checkOK,j,1) then
               if mid(Chr_Email,i,1) = "@" then
                  strCounter = strCounter + 1
               end if
               if mid(Chr_Email,i,1) = "." then
                  strCounter2 = strCounter2 + 1
               end if
               ok=TRUE
               exit for
            else
               ok=FALSE
            end if
         next
      next
      if ok=TRUE then
         if strCounter=1 and strCounter2>0 and inStr(Chr_Email,"..")=0 and inStr(Chr_Email,".@")=0 and inStr(Chr_Email,"@.")=0 and inStr(Chr_Email,"@")>2 and inStr(Chr_Email,"@")<>len(Chr_Email) and inStr(Chr_Email,".")>2 and inStr(Chr_Email,".")<>len(Chr_Email) then
            if len(chr_Email)-instrRev(Chr_Email,".")>1 and len(chr_Email)-instrRev(Chr_Email,".")<7 then
               strCounter= mid(chr_Email, instrRev(Chr_Email,".")+1, len(chr_Email))
               checkOK = "abcdefghijklmnopqrstuvwxyz"
               for i=1 to len(strCounter)
                  for j=1 to len(checkOK)
                     if mid(strCounter,i,1) = mid(checkOK,j,1) then
                        ok=TRUE
                        exit for
                     else
                        ok=FALSE
                     end if
                  next
                  if ok=FALSE then
                     exit for
                  end if
               next
            else
               ok=FALSE
            end if            
         else
            ok=FALSE
         end if
      end if
   end if
   validarEmail= Ok
end function