Created
January 29, 2019 05:50
-
-
Save fhdalikhan/023f5459030ac3f3f903e1403b906bbe to your computer and use it in GitHub Desktop.
This javascript function can be used to only allow typing of alphabets, & _ - and whitespace, it will remove all other characters, it uses a regex for this, you can modify to allow other characters, for example to allow numbers as well just add 0-9 to the regex after A-Z.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// Allow only alphabets & _ - whitespaces, strip out all others. | |
function clean(str) { | |
return str.replace(/[^a-z-A-Z\&\_\- ]/g, "").replace(/ +/, " ") | |
} | |
$('body').on('keyup', '#ask_message_textarea, #ask_message_title', function(event) { | |
this.value = clean(this.value); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment