Page 1 of 2

Valid email address

PostPosted: Fri Apr 10, 2009 3:24 pm
by Otto
Does someone have a function to check if a email address is valid.
Thanks in advance
Otto

Re: Valid email address

PostPosted: Fri Apr 10, 2009 7:55 pm
by ukoenig
Hello Otto,

I don't know, what You mean with valid. There are two tests possible :
Syntax-check ( text-input ) or If a Connection is possible.
If You want to collect E-Mail-addresses with possible connections, there is a freeware-solution for it.
If You need a solution for Syntax-check ( not easy ), I can give You some interesting links to German-forums.
Image
Program Description:
Mail List Validator verifies every e-mail address from a given mailing list, allows to determine about
90 % of dead e-mail addresses.

Another Solution : Fast Email Verifier ( not free of charge )
---------------------------------------------------------------------
FEV has the following features:
The fastest verifying of bad email addresses and invalid domains.
Easy ability to import email lists from CSV and TXT files.
Easy ability to import email addresses from external sources through ODBC SQL
Easy ability to export email addresses through ODBC SQL
Easy ability to export email addresses to Paradox, DBase, Excel, Text (.CSV), Word, SYLK, Lotus 1-2-3, QuattroPro, SQL script, XML, MS Access database files
Easy ability to import email addresses from Windows Address Book (.WAB)
Easy ability to synchronize verification results with Windows Address Book
Creates a detailed log for every operation.
Fast multi-threaded engines. The speed depends generally on the user's connection and Internet traffic.
Support of different mailing list formats.
Image

Regards
Uwe :lol:

Re: Valid email address

PostPosted: Sat Apr 11, 2009 2:58 am
by RAMESHBABU
Mr.Otto/Mr.Uwe,

>>If You need a solution for Syntax-check ( not easy ),

My following code is working Ok with me. You can try it if you need Syntax-check for e-mail address:

Code: Select all  Expand view

******************************************************************************
** 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
 


Regards,

- Ramesh Babu P

Re: Valid email address

PostPosted: Sat Apr 11, 2009 5:42 am
by Otto
Hello 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

Re: Valid email address

PostPosted: Sat Apr 11, 2009 8:00 am
by ukoenig
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 :lol:

Re: Valid email address

PostPosted: Sat Apr 11, 2009 8:02 am
by IBTC
Otto wrote:Are these your own functions:
FT_NOOCCUR


This function is from Nanforum Toolkit: http://www.somers.com.br/cgi-bin/w3ng.cgi?nanforlinux.ng+111289

Re: Valid email address

PostPosted: Sat Apr 11, 2009 8:35 am
by nageswaragunupudi
function NumAt( <cSearchfor>, <cString> ) --> nOccurances
in ct.lib ( available in harbour and xharbour )
can be used instead of FT_NOOCCUR

Re: Valid email address

PostPosted: Sat Apr 11, 2009 2:31 pm
by RAMESHBABU
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,

- Ramesh Babu P

Re: Valid email address

PostPosted: Sat Apr 11, 2009 5:28 pm
by Otto
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

Re: Valid email address

PostPosted: Sat Apr 11, 2009 5:56 pm
by Badara Thiam
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.

Re: Valid email address

PostPosted: Sun Apr 12, 2009 1:09 am
by RAMESHBABU
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,

- Ramesh Babu P

Re: Valid email address

PostPosted: Sun Apr 12, 2009 3:13 am
by sygecom
Hello,
Here's an example:

Code: Select all  Expand view
****************************
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
 

Re: Valid email address

PostPosted: Sun Apr 12, 2009 3:31 am
by nageswaragunupudi
The above function returns Valid for the following email address. Can this be right ?
Code: Select all  Expand view

Valid_Email( "..T.@TOM.COM.COM.COM.COM " ) --> returns .T.                                                                          
 

This address " .@a.com" passes Valid_Email but RameshBabu's function returns invalid

Re: Valid email address

PostPosted: Sun Apr 12, 2009 5:53 am
by hua
IBTC wrote:This function is from Nanforum Toolkit: http://www.somers.com.br/cgi-bin/w3ng.cgi?nanforlinux.ng+111289


Under xHarbour, Nanforum stuffs are in libnf.lib. Under Harbour it's hbnf.lib

Re: Valid email address

PostPosted: Sun Apr 12, 2009 7:39 am
by Otto
Hello,

when I posted my question I thought this is an easy task and not valid a question on the forum.
But going into details it seems not that easy.

http://en.wikipedia.org/wiki/E-mail_address

Now I know that an email is divided by an @ and that you have a local and a domain part.
The local-part of the e-mail address may use any of these ASCII characters:
• Uppercase and lowercase English letters (a-z, A-Z)
• Digits 0 through 9
• Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
• Character . provided that it is not the first nor last character, nor may it appear two or more times consecutively.
I added some more tests to RameshBabu's function.

Code: Select all  Expand view
//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




Best regards,
Otto