Choose Skin

Validate Email c# code



Manish Kumar
General

private void ValidateEmailAddress()
        {
            string email = txtemail.Text;
            Regex regex = new Regex(@"^([w.-]+)@([w-]+)((.(w){2,3})+)$");
            Match match = regex.Match(email);
            if (match.Success)
                lbl_message.Text=email + " is Valid Email Address";   
            else
                lbl_message.Text = email + " is Invalid Email Address";
        }

 

Regex EmailRegex = new Regex (@"^([w.-]+)@([w-]+)((.(w){2,3})+)$");

 

bool isEmail = Regex.IsMatch(emailString, @"A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)", RegexOptions.IgnoreCase);

 

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);

 

 

  1.  string email = txtEmail.Text;  
  2.             if (Regex.Match(email, @ "^([w.-]+)@([w-]+)((.(w){2,3})+)$").Success) {  
  3.                 lblMessage.Text = "Your Email (" + email + ") is Correct ";  
  4.                 lblMessage.TextColor = UIColor.Green;  
  5.             } else {  
  6.                 lblMessage.Text = "Your Email (" + email + ") is Incorrect ";  
  7.                 lblMessage.TextColor = UIColor.Red;  
  8.             }