KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Validating an E-Mail address
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: January 7, 2000
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Short of sending an E-Mail and seeing if it bounces there is very little to do to see if an E-Mail address is correct or not.

There are a few obvious things to look for.

1) No spaces in the name
2) One @ and only one @
3) The e-mail addess can not start or end with either a period "." or an "@"

Looking for the @ can be tricky because the @ is the wildcard character in 4D.

Below is a short code example of quickly testing for the most obvious errors in an E-Mail address errors. It returns True for a possible good address and False for a bad one.



Cut and Paste the following code example into your
own 4D project

If (False)
 ` Method: MAIL_fValidAddr(EMail) -> Boolean
 ` 4D Partner Referal WEB Database
 ` Created By: Kent D. Wilbur
 ` Date: 12/21/99

 ` Purpose: Checks to see if E-Mail address entered is valid.

 ` $1= E-Mail Address

 ` Variables for Insider
<>f_Version6x54:=True
<>fK_Wilbur:=True

End if

 ` Define parameters
C_BOOLEAN($0)
C_TEXT($1;$tEMailAddr)

 ` Define local varaibles
C_LONGINT($i)
C_LONGINT($LLength)
C_LONGINT($LPosition)

 ` Reassign for readability
$tEMailAddr:=$1

$0:=False  ` Assume the address is bad

$LPosition:=Position(" ";$tEMailAddr)  ` Look for a space

If ($LPosition=0) ` None found
 $LLength:=Length($tEMailAddr)

If (($tEMailAddr[[1]]=".") | (Ascii($tEMailAddr[[1]])=At sign ) | ($tEMailAddr[[$LLength]]=".") | (Ascii($tEMailAddr[[$LLength]])=At sign ))  ` First & Last should not be "." or "@"

 ` Reject the address
Else

 For ($i;2;$LLength-1)  ` First and last already checked
  If (Ascii($tEMailAddr[[$i]])=At sign )  `Is this an @
   If ($0)
    $0:=False ` Only one @
    $i:=$LLength  ` Second @ found don't look any more
   Else
    $0:=True  ` Set true for the first @
   End if
  End if
  End for

 End if
End if

  `End of method.