Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys

how to validation in email id textbox in desktop application pls guy tell me ?
Posted

Paste this code your Common.Cs
------------------------------------------
C#
public static bool isEmail(string inputEmail)
{
   if (inputEmail != "")
   {
     string strRegex = @"^([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})(\]?)$";
          Regex re = new Regex(strRegex);
          if (re.IsMatch(inputEmail))
              return (true);
          else
              return (false);
      }
      return (true);
  }




and in Codebehind;

SQL
if (Common.isEmail(txtbx_Email.Text))
           {

}
C#
else
            {
                MessageBox.Show("Email not valid!", "Save", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtbx_Email.Focus();
                return false;
            }
 
Share this answer
 
v3
Check every possible solution to similar problems here[^].
 
Share this answer
 
Comments
gauravrank 5-Aug-11 2:22am    
thanks
The most obvious way is with a regular expression. You can handle the event of the textbox losing focus, scan the regex and show a message/refocus the control. I do believe there's regex validators offered in winforms, too, although I may be wrong on that.
 
Share this answer
 
Comments
gauravrank 5-Aug-11 2:22am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900