Does someone have a function to check if a email address is valid.
Thanks in advance
Otto
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 lOkHello Ramesh Babu , hello Uwe,
Thank you for your help.
Your FUNCTION Validate_Email_Address will be soon included in my all.prg file.
Are these your own functions:
FT_NOOCCUR
YESNO
Uwe you had previous a link in your post with a newsgroup discussion
(GERMAN) about valid emails. I can’t find the link anymore.
I think I read – and I write sometimes emails to addresses with upper case in it – that upper case is also allowed.
Is this true?
And I also read that a valid email at least is 7 characters long.
Thank you for your help.
Best regards,
Otto
Hello Otto,
Here are the links to the sites for syntax-check.
I didn't know, if it could be useful for You.
There have been discussions about these problems, how to check in different ways.
Maybe there are still informations, You can need.
Informations :
A very good specification ( it is a lot, You have to allowing for ) :
http://aktuell.de.selfhtml.org/artikel/ ... ail-check/
some more :
http://www.phpugffm.de/pipermail/ugffm/ ... 02429.html
http://www.flashforum.de/forum/archive/ ... -8306.html
http://www.ayom.com/faq/wie-validiert-m ... a-252.html
http://www.delphipraxis.net/topic7231.html
Some software ( maybe useful ) :
http://wareseeker.com/free-email-syntax-checker/
Regards
Uwe ![]()
Otto wrote:
Are these your own functions:
FT_NOOCCUR
function NumAt( <cSearchfor>, <cString> ) --> nOccurances
in ct.lib ( available in harbour and xharbour )
can be used instead of FT_NOOCCUR
Hello Mr.Otto,
>Your FUNCTION Validate_Email_Address will be soon included in my all.prg file.
You are most welcome.
>Are these your own functions:
As Mr.Ruediger Alich said, FT_NOOCCUR is Nonforum toolkit function. And YesNo is my function.
Regards,
Hello Ramesh Babu,
I think we have to include Upper case and minus.
But I didn't found a definitive description what all is allowed, yet.
Best regards,
Otto
Mr Otto,
We can use upper or lower caracters in a email adress.
Like we want. This is not the same for domain name adress,
where upper and lower are differents.
Best Regards.
Mr.Otto,
I have edited my function above adding UPPER case letters and - (MINUS). And also validated
the length of the email. Please check.
Regards,
****************************
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 bValValid_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