Reputation: 75
I want my input for Name is cannot typing number mean it only allow letter Now I use like this:
var key = e.keyCode;
if (!((key == 8) || (key == 32) ||
(key == 46) || (key >= 35 && key <= 40) ||
(key >= 65 && key <= 90)))
{
e.preventDefault();
}
but It work on English letter only. Thank you for every help.
Upvotes: 1
Views: 82
Reputation: 949
Try this fiddle, it trigger's and rectifies on every input or change of the value to the control
$("#textbox").on("input",function(){
this.value=this.value.replace(/[^a-zA-Z]/gi, '')
})
Upvotes: 0
Reputation: 1905
Just use the built in pattern attribute in HTML.
<input type="text" pattern="[A-Za-z]" title="no numbers">
Upvotes: 4