private void PasswordText_TextChanged(object sender, EventArgs e) { if (!(String.IsNullOrEmpty(PasswordText.Text))) { if (!(char.IsLetterOrDigit(PasswordText.Text[PasswordText.Text.Length - 1]))) { MessageBox.Show("Please Enter Number or Letter!", "Notice", MessageBoxButtons.OK); string newPassword = ""; for (int i = 0; i < PasswordText.Text.Length - 1; ++i) { newPassword += PasswordText.Text[i]; } PasswordText.Text = newPassword; PasswordText.Select(PasswordText.Text.Length, 0); } } }