Reputation: 313
This is my javascript code ,
$(".onlyname").keypress(function (evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
if (charCode > 31 && (charCode < 65 || charCode > 90) &&
(charCode < 97 || charCode > 122)) {
return false;
} else {
return true;
});
It accepts only string values but it restrict the space key .How do I exclude space key?
Upvotes: 0
Views: 61
Reputation: 700342
Change the condition to exclude the space from the code that stops the event. Space has the code 32, so just change the lower boundary from 32 to 33:
if (charCode > 32 && (charCode < 65 || charCode > 90) &&
(charCode < 97 || charCode > 122)) {
Upvotes: 3