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. Web Development
  3. ASP.NET
  4. Email validation

Email validation

Scheduled Pinned Locked Moved ASP.NET
csharptutorial
5 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.
  • U Offline
    U Offline
    Uma Kameswari
    wrote on last edited by
    #1

    How to perform email validaiton for windows applicaions in .net

    S P 2 Replies Last reply
    0
    • U Uma Kameswari

      How to perform email validaiton for windows applicaions in .net

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

      Try this. I think it will help you. using System.Text.RegularExpressions; public static bool CheckEmailAddress(string strText) { //Validates the Email address string strPattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$"; return CheckRegExPattern(strPattern, strText.Trim()); } public static bool CheckRegExPattern(string strPattern, string strText) { return Regex.IsMatch(strText.Trim(), strPattern); }

      U 1 Reply Last reply
      0
      • U Uma Kameswari

        How to perform email validaiton for windows applicaions in .net

        P Offline
        P Offline
        psid23
        wrote on last edited by
        #3

        You can also try this piece of code. Assumptions: 1. Your Windows form has a text box with the name txtEmailID 2. You have using System.Text.RegularExpressions at the top of your form. 3. Call the ValidateEmail function in the event where you want to validate the email id. private bool ValidateEmail() { bool checkFlag = false; string EmailID = txtEmailID.Text.Trim(); if (EmailID != "") { Regex regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); Match match = regex.Match(EmailID); if (match.Length == EmailID.Length) { checkFlag = true; } else { MessageBox.Show("Enter a valid email-id"); checkFlag = false; txtEmailID.Focus(); } } else { MessageBox.Show("Enter Email ID"); txtEmailID.Focus(); } return checkFlag; } All the best. Siddharth P :)

        U 1 Reply Last reply
        0
        • S Suamal

          Try this. I think it will help you. using System.Text.RegularExpressions; public static bool CheckEmailAddress(string strText) { //Validates the Email address string strPattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$"; return CheckRegExPattern(strPattern, strText.Trim()); } public static bool CheckRegExPattern(string strPattern, string strText) { return Regex.IsMatch(strText.Trim(), strPattern); }

          U Offline
          U Offline
          Uma Kameswari
          wrote on last edited by
          #4

          HI Suamal, Thnak u for the help.It worked out. bye Uma

          1 Reply Last reply
          0
          • P psid23

            You can also try this piece of code. Assumptions: 1. Your Windows form has a text box with the name txtEmailID 2. You have using System.Text.RegularExpressions at the top of your form. 3. Call the ValidateEmail function in the event where you want to validate the email id. private bool ValidateEmail() { bool checkFlag = false; string EmailID = txtEmailID.Text.Trim(); if (EmailID != "") { Regex regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); Match match = regex.Match(EmailID); if (match.Length == EmailID.Length) { checkFlag = true; } else { MessageBox.Show("Enter a valid email-id"); checkFlag = false; txtEmailID.Focus(); } } else { MessageBox.Show("Enter Email ID"); txtEmailID.Focus(); } return checkFlag; } All the best. Siddharth P :)

            U Offline
            U Offline
            Uma Kameswari
            wrote on last edited by
            #5

            Hi Siddharth P, Thank u for the help. Uma

            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