javascript - Allow space in textbox -


so have code should allow letters typed in textbox, it's not allowing type space , need it:

js :

function onlyalphabets(e, t) {     try {         if (window.event) {             var charcode = window.event.keycode;         }         else if (e) {             var charcode = e.which;         }         else { return true; }         if ((charcode > 64 && charcode < 91) || (charcode > 96 && charcode < 123))             return true;         else             return false;     }     catch (err) {         alert(err.description);     } } 

question : should allow spaces ?

space char code 32.

so, should add or operator , check charcode == 32

like snippet:

if ((charcode > 64 && charcode < 91) || (charcode > 96 && charcode < 123) || charcode == 32) {   return true; } else {   return false; } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -