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:10 AM]
Checking An E-mail Address Is Correct !!
I don't have VB6 installed and don't have the help for taht function, but as i can see the function (implemented in VB6) should be something like this:
Function InStrRev(Str As String, ToFind As String)
Dim i As Integer
For i = Len(Str) To 1 Step -1
If Mid$(Str, i, 1) = ToFind Then Exit For
Next i
InStrRev = i
End Function
If you see, it's similar to the InStr() function, but it starts from the back. That's why the "Rev", from Reverse I guess.
Checking An E-mail Address Is Correct !!
I forgot to tell you this... but if you didn't understand it, you should place the code onto your project, and would work fine. However, the function posted before was right for this project, I guess it should be like this one (providing that the TextToFind may not be one character long):
Function InStrRev(Str As String, ToFind As String)
Dim i As Integer
For i = Len(Str) To 1 Step -1
If Mid$(Str, i, Len(ToFind)) = ToFind Then Exit For
Next i
InStrRev = i
End Function