|
-
Feb 14th, 2003, 04:45 PM
#1
Thread Starter
Addicted Member
Test for valid email address***resolved***
What would be the easiest way to test for valid email address in a text box. I will at least check for '@' and a '.' but what else can i do? What is the best way to test for those characters?
Thanks in advance.
Last edited by Halon; Feb 17th, 2003 at 03:54 PM.
Soylent Green tastes like chicken
-
Feb 14th, 2003, 05:08 PM
#2
Hyperactive Member
Just use InStr to make sure that they are actually in the string (if they aren't, a 0 will be returned). Then, make sure that the @ is at least the second character, and the period is at least one character after the @ and that there is at least two characters after the dot.
-
Feb 14th, 2003, 05:59 PM
#3
Hyperactive Member
VB Code:
Dim strEmail As String
If InStr(strEmail, "@") Then
If InStr(strEmail, ".") Then
MsgBox "Yep, there is a @ and a . "
Else
MsgBox "There is a @, but no ."
End If
Else
MsgBox "there is no @ so I didn't even se if there was a . in it"
End If
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Feb 14th, 2003, 09:44 PM
#4
Registered User
Slight modification, checks for the "." after the "@".
VB Code:
Dim strEmail As String
Dim iEmail As Integer
Dim iPeriod As Integer
iEmail = InStr(strEmail, "@")
iPeriod = InStr(iEmail, strEmail, ".")
If iEmail Then
If iPeriod And Len(strEmail) - iPeriod >= 2 Then
MsgBox "Yep, there is a @ and a . "
Else
MsgBox "There is a @, but no . in the domain name"
End If
Else
MsgBox "there is no @ so I didn't even se if there was a . in it"
End If
Just in case they enter blah.blah@blahcom
Also makes sure there are at least 2 characters after the ".".
Do you have any other requirements for determining a valid email address?
s.
-
Feb 17th, 2003, 03:54 PM
#5
Thread Starter
Addicted Member
Thanks guys!! Instr was what i was using in the beginning but i thought there may have been some advancements in validation code, maybe i'll write a textbox control and have it test the string based on the code from silva and carp.
Cheers
Soylent Green tastes like chicken
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
|