TextBox Validation
-
How make validatin that whitespace are not allowed in textbox? How i get the key code of press key?
-
How make validatin that whitespace are not allowed in textbox? How i get the key code of press key?
There are two different things you can do: 1. Handle
Validating
event for theTextBox
, and use regular expressions to validate that no spaces are in the string the user entered, and if yes, don't allow the user to go to another control before correcting it. 2. In theKeyDown
event, if the key is a space, sete.Handled = true
, so theTextBox
doesn't handle it, effectively eating the keystroke. -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
-
There are two different things you can do: 1. Handle
Validating
event for theTextBox
, and use regular expressions to validate that no spaces are in the string the user entered, and if yes, don't allow the user to go to another control before correcting it. 2. In theKeyDown
event, if the key is a space, sete.Handled = true
, so theTextBox
doesn't handle it, effectively eating the keystroke. -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
i tried using this but it does not work i tried using this sample code. private void textBox1_KeyDown(object sender,System.Windows.Forms.KeyEventArgs e) { if(e.KeyValue==65) { e.Handled=true; } } it still prints the character 'a' in the text box
-
i tried using this but it does not work i tried using this sample code. private void textBox1_KeyDown(object sender,System.Windows.Forms.KeyEventArgs e) { if(e.KeyValue==65) { e.Handled=true; } } it still prints the character 'a' in the text box