only allow English characters and numbers for text input

0
I added this code in javascript snippet but its not working as expected. $('.mx-name-textArea5').keypress(function(event){     var ew = event.which;     if(ew == 32)         return true;     if(48 <= ew && ew <= 57)         return true;     if(65 <= ew && ew <= 90)         return true;     if(97 <= ew && ew <= 122)         return true;     return false; });   Please suggest what to add/modify in it.   Error: When I am entering any alphabet apart from english its also taking it. 
asked
2 answers
0

Nothing wrong with the javascript. It returns true whenever you hit enter, 0-9, A-Z or a-z. False otherwise.

So describe the error behavior. What is it doing/not doing?

answered
0

Try this, comparing with key directly using regex instead of keycode 

var ew = event.key;
if( /[A-Za-z0-9 ]/.test(ew))
return true;

 

answered