How disallow space, blank, ("_") character from text box input by keyboard (WPF, C#)?
I try by code:
Regex regex = new Regex(@"^[A-Za-z0-9\[\]/!$%^&*()\-_+{};:'£@#.?]*$");
but this part of code disallow all character, but not space.
You can add PreviewKeyDown handler:
private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
{
e.Handled = true;
}
}
Now your textbox will ignore spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With