FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Validar e-mail usando Regex (SOLUCIONADO)
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Validar e-mail usando Regex (SOLUCIONADO)
Posted: 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
Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: Validar e-mail usando Regex (SOLUCIONADO)
Posted: Sun Feb 04, 2024 03:58 AM
Code (fw): Select all Collapse
#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-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Validar e-mail usando Regex (SOLUCIONADO)
Posted: Sun Feb 04, 2024 04: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

Continue the discussion