FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Valid email address
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Valid email address
Posted: Fri Apr 10, 2009 03:24 PM

Does someone have a function to check if a email address is valid.
Thanks in advance
Otto

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Valid email address
Posted: Fri Apr 10, 2009 07:55 PM
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.

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.


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Valid email address
Posted: Sat Apr 11, 2009 02:58 AM
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 (fw): Select all Collapse
******************************************************************************
** 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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Valid email address
Posted: Sat Apr 11, 2009 05:42 AM

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

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Valid email address
Posted: Sat Apr 11, 2009 08:00 AM

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:

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 103
Joined: Sat Oct 18, 2008 08:13 PM
Re: Valid email address
Posted: Sat Apr 11, 2009 08:02 AM
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
Best Regards,

Ruediger Alich



---

HMG 3.1.3 | FTDN/FWH 13.12 | Harbour 3.2 | BCC/MinGW | Windows XP/Vista/7/8/10 (32/64-Bit), Wine (Linux/Mac) - started 1999 with FW, 1989 with Clipper
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Valid email address
Posted: Sat Apr 11, 2009 08:35 AM

function NumAt( <cSearchfor>, <cString> ) --> nOccurances
in ct.lib ( available in harbour and xharbour )
can be used instead of FT_NOOCCUR

Regards



G. N. Rao.

Hyderabad, India
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Valid email address
Posted: Sat Apr 11, 2009 02:31 PM

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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Valid email address
Posted: Sat Apr 11, 2009 05:28 PM

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

Posts: 160
Joined: Tue Oct 18, 2005 10:21 AM
Re: Valid email address
Posted: Sat Apr 11, 2009 05:56 PM

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.

Badara Thiam
http://www.icim.fr
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Valid email address
Posted: Sun Apr 12, 2009 01:09 AM

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
Posts: 58
Joined: Tue Mar 11, 2008 03:18 AM
Re: Valid email address
Posted: Sun Apr 12, 2009 03:13 AM
Hello,
Here's an example:

Code (fw): Select all Collapse
****************************
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Valid email address
Posted: Sun Apr 12, 2009 03:31 AM
The above function returns Valid for the following email address. Can this be right ?
Code (fw): Select all Collapse
Valid_Email( "..T.@TOM.COM.COM.COM.COM " ) --> returns .T.

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



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Valid email address
Posted: Sun Apr 12, 2009 05:53 AM
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
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Valid email address
Posted: Sun Apr 12, 2009 07:39 AM
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 (fw): Select all Collapse
//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