Textbox with alphanumeric check in javascript

后端 未结 5 1151
失恋的感觉
失恋的感觉 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 01:51

    This function will check the string given to it for those criteria:

    function checkvalue(value) {
      return value.match( /[A-Za-z][A-Za-z0-9 ]*/ );
    }
    

    You can then use that in an onkeypress event, passing in the current value.

提交回复
热议问题