Textbox with alphanumeric check in javascript

后端 未结 5 1161
失恋的感觉
失恋的感觉 2020-12-12 01:37

I have a textbox, and it needs not allow the user to enter any special characters. He can enter:

  1. A-Z
  2. a-z
  3. 0-9
  4. Space.

O

5条回答
  •  醉酒成梦
    2020-12-12 02:03

    You should check pressed key in onkeydown event handler of the textbox and if it doesn't conform conditions then return false from the handler. Using keyup will not allow you to prevent char from being actually inputted in the textbox.

提交回复
热议问题