0

I have a Textbox and the following code to allow only numbers:

textBox1.Text = Regex.Replace(textBox1.Text, "[^\\d]", "");

Now when I type another key than numbers, the focus goes to the beginning of the Textbox...What do I need to not let this happen?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
asdasdad
  • 832
  • 3
  • 15
  • 27

2 Answers2

1

Don't ask how to remove numbers. Ask how to make a textbox for numbers only: How do I make a textbox that only accepts numbers?

Community
  • 1
  • 1
usr
  • 168,620
  • 35
  • 240
  • 369
1

Use MaskedTextBox instead, specifying the Mask property.

abatishchev
  • 98,240
  • 88
  • 296
  • 433