How to prevent user from entering special characters in text box when length is 0?

前端 未结 3 1794
盖世英雄少女心
盖世英雄少女心 2020-12-11 01:13

I have the following code which prevents user from entering space when the length is 0. Now, how can I prevent user from entering all special characters(anything other than

3条回答
  •  粉色の甜心
    2020-12-11 01:36

    You can use a regex to validate the string. Something like ^[a-zA-z0-9].*

    Here is an article about testing a regex in javascript : http://www.w3schools.com/jsref/jsref_regexp_test.asp

    And you can even bind a change event and not a keypress.

提交回复
热议问题