Does someone have a function to check if a email address is valid.
Thanks in advance
Otto
******************************************************************************
** FUNCTION Validate_Email_Address(cE_Mail) to Validate the entry of e.mail **
** address **
******************************************************************************
FUNCTION Validate_Email_Address(cE_Mail)
LOCAL lOk := .T., cValid_Letters := "abcdefghijklmnopqrstuvwxyz"+;
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"+;
"0123456789._-@"
LOCAL n
cE_Mail := ALLTRIM(cE_Mail)
* If you want empty email
IF EMPTY(cE_Mail)
RETURN .T.
ENDIF
DO CASE
* Check for minimum length of the email address i.e. 8
CASE LEN(ALLTRIM(cE_Mail)) < 8
lOk := .F.
* Check for existance of '@' and '.' the basic characters of an email
CASE (.NOT. "@" $ cE_Mail) .OR. (.NOT. "." $ cE_Mail)
lOk := .F.
* Check '@' is typed more than the required 1 time (Nonforum toolkit function)
CASE FT_NOOCCUR("@",cE_Mail,.F.) >1
lOk := .F.
* Check wether any characters are between '@' and '.' or type continuous
CASE ( RAT(".", cE_Mail) - AT("@", cE_Mail) <= 2 )
lOk := .F.
OTHERWISE
FOR n = 1 TO LEN(cE_Mail)
IF .NOT. SUBSTR(cE_Mail,n,1) $ cValid_Letters
lOk := .F.
EXIT
ENDIF
NEXT
ENDCASE
IF .NOT. lOk
Alert("The E.Mail address you have entered does not seem to be valid;"+ ;
"E.Mail address. Please Check.")
ENDIF
RETURN lOk
Otto wrote:Are these your own functions:
FT_NOOCCUR
****************************
Function Valid_Email(cmail)
****************************
Local oRegEx, bVal
TRY
oRegEx := Createobject("VBScript.RegExp")
CATCH error
RETURN .T.
END
oRegEx:Pattern :="^[\w-\.]{1,}\@([\da-zA-Z-_]{1,}\.){1,}[\da-zA-Z-_]{2,3}$"
cmail := ALLTRIM(cmail)
bVal := oRegEx:Test(cMail)
Release oRegEx
Return bVal
Valid_Email( "..T.@TOM.COM.COM.COM.COM " ) --> returns .T.
IBTC wrote:This function is from Nanforum Toolkit: http://www.somers.com.br/cgi-bin/w3ng.cgi?nanforlinux.ng+111289
//local-part - there must be a local part
cToken := StrToken( cE_Mail,1,'@' )
nLocalPart := len( ALLTRIM(cToken) )
if nLocalPart = 0 .or. nLocalPart > 64
lOk := .F.
endif
//domain-part
cDomainpart := StrToken( cE_Mail,2,'@' )
* Check domain-part if '.' is typed more than the required 1 time
nAnzPunkte := NumAt( ".",cDomainpart )
FOR I := 1 to nAnzPunkte + 1
cToken := StrToken( cDomainpart,I,'.' )
if I = nAnzPunkte
if len(ALLTRIM(cToken)) < 2
lOk := .F.
endif
else
if len(ALLTRIM(cToken)) < 1
lOk := .F.
endif
endif
next
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 104 guests