|
-
Apr 6th, 2000, 09:54 PM
#1
Thread Starter
New Member
Checking An E-mail Address Is Correct !!
Hello,
I have received the following code to verify that an e-mail address is correctly typed into a text box to be passed into an Access 97 table.
The code runs fine in VB 6 but I also need it to run in VB 5. When I run the code in VB 5 I get the following error message: "Complie Error" "Sub or Function Not Defined"
then when I click 'debug' the following piece of code is highlighted within the module code: InStrRev
I would greatly appreciate any help, links or code as to why this is happennig or even a way of getting around it within VB 5. The code I am using is below...
Thanks,
Andy.............
Code:
Function checkValidEmail(theAddress) As Boolean
'http://www.4guysfromrolla.com/webtech/051999-1.shtml
On Error GoTo ExitFalse
' checks for a valid email
' returns false for invalid addresses
Dim atCnt
checkValidEmail = True
' chk length
If Len(theAddress) < 5 Then
' [email protected] should be the shortest an
' address could be
checkValidEmail = False
' chk format
' has at least one "@"
ElseIf InStr(theAddress, "@") = 0 Then
checkValidEmail = False
' has at least one "."
ElseIf InStr(theAddress, ".") = 0 Then
checkValidEmail = False
' has no more than 3 chars after last "."
ElseIf Len(theAddress) - InStrRev(theAddress, ".") > 3 Then
checkValidEmail = False
' has no "_" after the "@"
ElseIf InStr(theAddress, "_") <> 0 And _
InStrRev(theAddress, "_") > InStrRev(theAddress, "@") Then
checkValidEmail = False
Else
' has only one "@"
atCnt = 0
For i = 1 To Len(theAddress)
If Mid(theAddress, i, 1) = "@" Then
atCnt = atCnt + 1
End If
Next
If atCnt > 1 Then
checkValidEmail = False
End If
' chk each char for validity
For i = 1 To Len(theAddress)
If Not IsNumeric(Mid(theAddress, i, 1)) And _
(LCase(Mid(theAddress, i, 1)) < "a" Or _
LCase(Mid(theAddress, i, 1)) > "z") And _
Mid(theAddress, i, 1) <> "_" And _
Mid(theAddress, i, 1) <> "." And _
Mid(theAddress, i, 1) <> "@" And _
Mid(theAddress, i, 1) <> "-" Then
checkValidEmail = False
End If
Next
End If
Exit Function
ExitFalse:
checkValidEmail = False
Exit Function
End Function
[Edited by AndyCapp on 04-07-2000 at 11:12 AM]
-
Apr 8th, 2000, 01:48 PM
#2
Conquistador
here is a contribution of some code from me too.
Code:
Function CheckValidEmail(Email As String) As Boolean
Dim strIndex, i As Integer, myStr As String, Valid@, ValidDot As Boolean
Valid@ = False
ValidDot = False
For i = 0 To Len(Email)
myStr = Left(Email, i)
myStr = Right(myStr, 1)
If myStr = "@" Then
Valid@ = True
If ValidDot = True Then
CheckValidEmail = True
Exit For
End If
End If
If myStr = "." Then
ValidDot = True
If Valid@ = True Then
CheckValidEmail = True
Exit For
End If
End If
Next i
End Function
oh well hope it helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|