Restrict numbers and letters in textbox - C#

前端 未结 6 1555
心在旅途
心在旅途 2021-01-24 10:35

I want to restrict what numbers and letters can be entered into a textbox. Let\'s say I only want to allow numbers 0-5 and letters a-d (both lower and uppercase). I already tri

6条回答
  •  遥遥无期
    2021-01-24 11:17

    The Keypress event is probably your best bet. Do a check there if the entered char is not the char you want, set e.SuppressKey to true to make sure the KeyPress event is not fired, and the char is not added to the textbox.

提交回复
热议问题