I recently watched a tutorial on YouTube by the developphp guy and learned how to prevent people from inputting inappropriate words in my form's text area.
However, I want to block multiple words instead of just one, but the tutorial didn't cover that. I've been trying to find a solution without success. Can someone please help me?
Here is the current JavaScript code:
HTML
<textarea class="ta" id="ta" name="ta" onkeyup="clean('ta')" onkeydown="clean('ta')" placeholder="Enter a positive message"></textarea>
JAVASCRIPT
<script type="text/javascript">
function clean(el){
var textfield = document.getElementById(el);
var regex = /badword1|badword2/gi;
if(textfield.value.search(regex) > -1) {
textfield.value = textfield.value.replace(regex, "");
}
}
</script>
Thank you for your assistance!