a textreplace isn’t working in my case. i need an error shown up when a user leaves the box when he types more then one \
If this is what you really want you need to use a ErrorProvider. Add one to your form then add the following code to the texbox’s Validating
event and be sure that CausesValidation
is true for the textbox
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if(Regex.IsMatch(textBox1.Text, @"\\\\+"))
{
e.Cancel = true;
errorProvider1.SetError(textbox1, @"\\ Is not allowed");
}
else
{
errorProvider1.SetError(textbox1, null);
}
}
This will make a !
show up next to the text box if they type wrong and force them to correct it when they attempt to leave the text box.
solved Textbox don’t allow typing ” \ ” 2 times after each other [duplicate]