Results 1 to 5 of 5

Thread: Test for valid email address***resolved***

  1. #1

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228

    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

  2. #2
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    Toronto, Ontario
    Posts
    280
    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.

  3. #3
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    VB Code:
    1. Dim strEmail As String
    2. strEmail = "[email protected]"
    3.  
    4. If InStr(strEmail, "@") Then
    5.     If InStr(strEmail, ".") Then
    6.         MsgBox "Yep, there is a @ and a . "
    7.     Else
    8.         MsgBox "There is a @, but no ."
    9.     End If
    10. Else
    11.     MsgBox "there is no @ so I didn't even se if there was a . in it"
    12.    
    13. End If
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    Slight modification, checks for the "." after the "@".

    VB Code:
    1. Dim strEmail As String
    2. Dim iEmail As Integer
    3. Dim iPeriod As Integer
    4. strEmail = "[email protected]"
    5.  
    6. iEmail = InStr(strEmail, "@")
    7.  
    8. iPeriod = InStr(iEmail, strEmail, ".")
    9.  
    10. If iEmail Then
    11.     If iPeriod And Len(strEmail) - iPeriod >= 2 Then
    12.         MsgBox "Yep, there is a @ and a . "
    13.     Else
    14.         MsgBox "There is a @, but no . in the domain name"
    15.     End If
    16. Else
    17.     MsgBox "there is no @ so I didn't even se if there was a . in it"
    18. 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.

  5. #5

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    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
  •  



Click Here to Expand Forum to Full Width