Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to check a text box for a valid email address

How to check a text box for a valid email address

Scheduled Pinned Locked Moved Visual Basic
comtutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eshban284
    wrote on last edited by
    #1

    Hello, I attach a textbox on the form. How can i check a text box for a valid email address. Means if user enters invalid address in a text box e.g (aaaa.com), then it will alert a message. plz reply. EsHbAn BaHaDuR

    S D 2 Replies Last reply
    0
    • E eshban284

      Hello, I attach a textbox on the form. How can i check a text box for a valid email address. Means if user enters invalid address in a text box e.g (aaaa.com), then it will alert a message. plz reply. EsHbAn BaHaDuR

      S Offline
      S Offline
      sumit21
      wrote on last edited by
      #2

      u can force user to enter valid email u can force him to enter username(just username) in one textbox and domain(e.g. rediff, yahoo) in another username (textbox here) @ domain(textbox here) then u can cancatenate string as dim str as string=textbox1.text+"@"+textbox2.text i think this logic will work all the best

      D 1 Reply Last reply
      0
      • S sumit21

        u can force user to enter valid email u can force him to enter username(just username) in one textbox and domain(e.g. rediff, yahoo) in another username (textbox here) @ domain(textbox here) then u can cancatenate string as dim str as string=textbox1.text+"@"+textbox2.text i think this logic will work all the best

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        That's a horrible solution considering it allows for all kinds of invalid characters in the address... A better solution is to use a Regular Expression to do the validation. There are many examples of this all over the web. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        1 Reply Last reply
        0
        • E eshban284

          Hello, I attach a textbox on the form. How can i check a text box for a valid email address. Means if user enters invalid address in a text box e.g (aaaa.com), then it will alert a message. plz reply. EsHbAn BaHaDuR

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Use a Regular Expression (RegEx class) to evaluate if the address is sytactically correct:

          Public Function IsEmail(ByVal emailAddress As String) As Boolean
          Dim strRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & _
          @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" & _
          @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
          Dim re As New Regex(strRegex)
          If re.IsMatch(emailAddress)
          Return True;
          Else
          Return False
          End Function

          * Code snippet taken from this[^] Code Project article by Vasudevan Deepak Kumar. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups