How can i restrict user from entering the numeric and special characters in textbox?

921 Views Asked by At

I want that while entering the textbox, user is unable to enter the special character and numerical values. I don't want any alert or any span to display error. I just want that the numerical value or special character should not be displayed in the textbox. How can i do that? Thanks in advance.

1

There are 1 best solutions below

1
On BEST ANSWER

As simple as this

<input name="lorem" onkeyup="this.value=this.value.replace(/[^a-z]/g,'');">

same goes for onblur

Using jquery if you need:

$('#textBoxId').on('keyup blur',function(){ 
    var node = $(this);
    node.val(node.val().replace(/[^a-z]/g,'') ); }
);