You are on page 1of 1

private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { //define a string containing special characters string arr = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?

"; for (int k = 0; k < arr.Length; k++) { if (e.KeyChar== arr[k]) { MessageBox.Show("special characters not allowed"); e.Handled = true; break; } } }

You might also like