Validar e-mail usando Regex (SOLUCIONADO)

Validar e-mail usando Regex (SOLUCIONADO)

Postby Armando » Sun Feb 04, 2024 12:14 am

Foreros:

Alguien valida la dirección de correo electrónico usando una expresión regular (Regex) y quiera compartirlo?

Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3061
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Validar e-mail usando Regex (SOLUCIONADO)

Postby Cgallegoa » Sun Feb 04, 2024 3:58 am

Code: Select all  Expand view

#Include "FiveWin.ch"
#include "hbcompat.ch"

Function Inicio()
MsgInfo(cValToChar(validaEmail("tuemail@tuservidor.com")))     // .T.
MsgInfo(cValToChar(validaEmail("tuemail$tuservidor.com")))      // .F.
MsgInfo(cValToChar(validaEmail("tuemail@tuservidor%com")))    // .F.
MsgInfo(cValToChar(validaEmail("tuemail@tuservidorcom")))      // .F.
MsgInfo(cValToChar(validaEmail("tuemail@tuservidor")))            // .F.
etc, etc, etc
Return(NIL)

function validaEmail(cEmail)
    LOCAL pCompiled := hb_regexComp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$")
    LOCAL aMatch
    LOCAL lRet := .t.
    aMatch = hb_regex( pCompiled, alltrim(cEmail) )
    if Empty( aMatch )
        lRet := .f.
    end
return lRet
 
Saludos,

Carlos Gallego

*** FWH-23.10, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
Cgallegoa
 
Posts: 414
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Validar e-mail usando Regex (SOLUCIONADO)

Postby Armando » Sun Feb 04, 2024 4:00 am

Carlos:

Muchas gracias.

Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3061
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests