Prevent users typing special characters in text box, textarea, etc.
1 2 3 4 5 |
$(document).on('keypress',':text,textarea', function () { if (this.value.match(/[^a-z0-9@,.'\-_) (]/gi)) { // now accept @ , - " this.value = this.value.replace(/[^a-z0-9@,.'\-_) (]/gi,''); } }); |
^[a-zA-Z]+$ | Alphabets |
^[a-zA-Z\s]+$ | Alphabets + Space |
Example:-