Violeta Popa

Violeta Popa

  • NA
  • 137
  • 163.8k

validate a textbox-error provider

Apr 7 2013 7:30 AM
Hi! i want to validate a textbox, where the email is introduces. First i check if the email is too short, and it works, then i try to check if it ends with @yahoo.com or @gmail.com but it doesn't work fine. I guess it's a problem with Substring. Any help? thks.

 private void emailTxt_Validating(object sender, CancelEventArgs e)
        {
            string mesaj = null;
            string email = emailTxt.Text;
            int lungime = email.Length;

            if (lungime < 11)
            {
                mesaj = "E-mail prea scurt!";
                this.errorProvider1.SetError(this.emailTxt, mesaj);
            }
            else
            {
                string text = email.Substring(lungime - 12, 10);
                if (text != "@yahoo.com" || text != "@gmail.com")
                {
                    mesaj = "E-mail: [email protected] sau [email protected]!";
                    this.errorProvider1.SetError(this.emailTxt, mesaj);
                }
            }
        }

Answers (1)