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
  • 95,331
  • 80
  • 293
  • 426
asdasdad
  • 844
  • 3
  • 14
  • 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
  • 165,323
  • 34
  • 234
  • 359
1

Use MaskedTextBox instead, specifying the Mask property.

abatishchev
  • 95,331
  • 80
  • 293
  • 426