C# .NET - textbox accepting only minus sign in c#

Asked By Deven on 15-Apr-13 03:34 AM

Hello,
How shall we make textbox allow only minus sign on textchanged event.
Kindly help me.
shital patil replied to Deven on 19-Apr-13 06:37 AM
Hi,

Please try following code:
   
private void textBox1_TextChanged(object sender, EventArgs e)
{      
  if (!System.Text.RegularExpressions.Regex.IsMatch("^[-]", textBox1.Text))
  {
    textBox1.Text= textBox1.Text.Remove(textBox1.Text.Length - 1);
  }
   
}