I have a textBox called txtSSID
and I want to validate that only letters (not all), numbers and some special characters are entered:
Do not allow letters like the ones I detail below (Uppercase or lowercase):
'é', 'ý', 'ú', 'í', 'ñ', 'ó', 'á', 'ë', 'ÿ', 'ü', 'ï', 'ö' , 'ä', 'ê', 'û', 'î', 'ô', 'â'
I have this code:
char[] NoPermitir = { 'é', 'ý', 'ú', 'í', ' ', 'ñ', 'ó', 'á', 'ë', 'ÿ', 'ü', 'ï', 'ö', 'ä','ê','û','î','ô','â'};
Allow special character like the ones I detail below:
'-', '_'
I have this code:
char[] Permitir = { '-', '_'};
This is the complete code that validates all the letters including ñ, accents and other Spanish characters which I do not want to be, validates numbers and admits the BakcSpace
( The key that is used to delete) this is the code:
private void txtSSID_KeyPress(object sender, KeyPressEventArgs e)
{
char[] NoPermitir = { 'é', 'ý', 'ú', 'í', 'ñ', 'ó', 'á', 'ë', 'ÿ', 'ü', 'ï', 'ö', 'ä','ê','û','î','ô','â'};
char[] Permitir = { '-', '_'};
if (!(char.IsLetter(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) && !(char.IsNumber(e.KeyChar)))
{
MessageBox.Show("Solo se permiten letras y números", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Handled = true;
return;
}
if (String.IsNullOrEmpty(txtSSID.Text))
{
label1.Text = "Error";
}
else
{
label1.Text = "Correcto";
}
}
How can I also validate Char[] Permitir
and Char[]NoPermitir
in my textBox txtSSID
.