Email validation (1 Viewer)

antonellac

Registered User.
Local time
Today, 21:58
Joined
Aug 15, 2004
Messages
15
This time we are to validate an e-mail address. I have looked over the net and found out a function to use http://forums.aspfree.com/showthread.php?p=98009#post98009 . However, it appears that it does not work on VB for applications basically because I'm not allowed to declare new regexp (an error occurs).

We therefore require your help to solve us this problem.

Once again this is a thesis related question and therefore your urgent reply would be appreciated.

Best Regards,
Antonella
University of Malta
 

scouser

Registered User.
Local time
Today, 20:58
Joined
Nov 25, 2003
Messages
767
Try this

Try this from Mile-O:
Code:
Private Sub EmailAddress_BeforeUpdate(Cancel As Integer)
' Validates the email address entered
Dim intAtPoint As Integer, intDomain As Integer
    Dim boo As Boolean, strAddress As String
    
    If IsNull(Me.EmailAddress) Then Exit Sub ' If the email field is blank then exit
    
    strAddress = Trim(Me.EmailAddress)
    
    intAtPoint = InStr(1, strAddress, "@")
    
    If intAtPoint Then
        If ((intAtPoint = 1) Or (intAtPoint = Len(strAddress))) Then
            boo = True
            GoTo Invalid
        End If
    Else
        boo = True
        GoTo Invalid
    End If
    
    intDomain = InStr(intAtPoint, strAddress, ".")
    
    If intDomain Then
        If ((intDomain = (intAtPoint + 1)) Or (intDomain = Len(strAddress))) Then
            boo = True
            GoTo Invalid
        End If
    Else
        boo = True
        GoTo Invalid
    End If
    
Invalid:
    If boo = True Then
        MsgBox "This is not a valid email address.", vbExclamation, gAPPNAME
        Cancel = True
    End If
End Sub
Hope that helps,
Phil.
 

Users who are viewing this thread

Top Bottom