How to filter textbox input to numeric only?

前端 未结 9 1522
耶瑟儿~
耶瑟儿~ 2020-12-21 13:37

How do I suppress all data except numeric?

This is not working on KeyDown():

If e.KeyData < Keys.D0 Or e.KeyData > Keys.D9 Then
          


        
9条回答
  •  自闭症患者
    2020-12-21 14:31

    The purpose of your function could help provide additional solutions. Checking for a numeric value on each KeyPress is likely overkill. Then you have to overkill it more by accounting for backspace, delete, copy, paste, etc.

    For example, if you are storing a telephone number, you should use the "IsNumeric" function on the validate and update step. Alternatively, if you are selecting quantity of an item "NumericUpDown" control would be more appropriate than a TextBox.

提交回复
热议问题