Textbox with alphanumeric check in javascript

后端 未结 5 1157
失恋的感觉
失恋的感觉 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:08

    Now that we have HTML5, you don't even need to use JavaScript. You can use the pattern attribute.

    
    

    The pattern attribute should contain a regular expression defining the format. And title should contain a human-readable description of the format.

    Then on validation, depending on the browser, the browser will outline the field in red and/or display a message stating your description of the format.

    This tutorial goes into more detail: HTML5 Input Validation Tutorial.

提交回复
热议问题