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. C#
  4. Validating Email Address

Validating Email Address

Scheduled Pinned Locked Moved C#
comhelpquestion
5 Posts 5 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.
  • D Offline
    D Offline
    dabuskol
    wrote on last edited by
    #1

    Hi, How can I validate the email Address in a textbox with multiple information. The same validation in yahoo when you add email add, if email add is not correct there is an error message. Sample. dvd@yahoo.com; exevl@hotmail.com -- > correct (semicolon) dvd@yahoo.com exevl@hotmail.com -- > correct (space) James borlan [ James@yahoo.com] -- > incorrect james@yahoo.com Donald@yahoo.com [All email] - incorrect Thanks Dabuskol

    Dabsukol

    S G W S 4 Replies Last reply
    0
    • D dabuskol

      Hi, How can I validate the email Address in a textbox with multiple information. The same validation in yahoo when you add email add, if email add is not correct there is an error message. Sample. dvd@yahoo.com; exevl@hotmail.com -- > correct (semicolon) dvd@yahoo.com exevl@hotmail.com -- > correct (space) James borlan [ James@yahoo.com] -- > incorrect james@yahoo.com Donald@yahoo.com [All email] - incorrect Thanks Dabuskol

      Dabsukol

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

      use pattern matching .

      1 Reply Last reply
      0
      • D dabuskol

        Hi, How can I validate the email Address in a textbox with multiple information. The same validation in yahoo when you add email add, if email add is not correct there is an error message. Sample. dvd@yahoo.com; exevl@hotmail.com -- > correct (semicolon) dvd@yahoo.com exevl@hotmail.com -- > correct (space) James borlan [ James@yahoo.com] -- > incorrect james@yahoo.com Donald@yahoo.com [All email] - incorrect Thanks Dabuskol

        Dabsukol

        G Offline
        G Offline
        goldli
        wrote on last edited by
        #3

        http://regexlib.com/Search.aspx?k=ip+address code below matchs ip string RegString = @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$"; Regex RegObj = new Regex(RegString); if (!RegObj.IsMatch(ipString)) MessageBox.Show("error", MessageBoxButtons.OK, MessageBoxIcon.Error);

        1 Reply Last reply
        0
        • D dabuskol

          Hi, How can I validate the email Address in a textbox with multiple information. The same validation in yahoo when you add email add, if email add is not correct there is an error message. Sample. dvd@yahoo.com; exevl@hotmail.com -- > correct (semicolon) dvd@yahoo.com exevl@hotmail.com -- > correct (space) James borlan [ James@yahoo.com] -- > incorrect james@yahoo.com Donald@yahoo.com [All email] - incorrect Thanks Dabuskol

          Dabsukol

          W Offline
          W Offline
          Wayne Phipps
          wrote on last edited by
          #4

          This will match the pattern of an email address using a regex expression:

          		public bool EmailValid(string email)
          		{
          			string _expression = @"^([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})(\]?)$";
          			
          			return System.Text.RegularExpressions.Regex.IsMatch( email, _expression );
          		}
          

          Hope this helps

          Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog

          1 Reply Last reply
          0
          • D dabuskol

            Hi, How can I validate the email Address in a textbox with multiple information. The same validation in yahoo when you add email add, if email add is not correct there is an error message. Sample. dvd@yahoo.com; exevl@hotmail.com -- > correct (semicolon) dvd@yahoo.com exevl@hotmail.com -- > correct (space) James borlan [ James@yahoo.com] -- > incorrect james@yahoo.com Donald@yahoo.com [All email] - incorrect Thanks Dabuskol

            Dabsukol

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            See this thread: http://www.codeproject.com/script/comments/forums.asp?forumid=1649&Page=4&userid=157870&mode=all&select=1800655&df=100&fr=12754.5#xx1800655xx[^] The bottom line is that regular expressions will catch most of the more commonly used forms for email addresses, but not all of them. It all depends on how strictly you want to follow the RFC specs. You can also use the MailAddress[^] class in .NET 2.0, which works for almost all of the valid RFC formats (but there are a few of the more complicated and seldom used formats that it also doesn't get right).

            ----------------------------- In just two days, tomorrow will be yesterday.

            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