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
You can use a regex to validate the string. Something like ^[a-zA-z0-9].*
^[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.