I've been watching a tutorial from developphp guy from youtube. I want to avoid people to write bad words on my text area from my form.
But I want to prevent them from writting several words, not only one, this tutorial doesn't explain that and I'm trying to find a way without succees, can someone explain me?
this is the actual javascript
HTML
<textarea class="ta" id="ta" name="ta" onkeyup="clean('ta')" onkeydown="clean('ta')" placeholder="A good word for a good word"></textarea>
JAVASCRIPT
<script type="text/javascript">
function clean(el){
var textfield = document.getElementById(el);
var regex = /fuck/gi;
if(textfield.value.search(regex) > -1) {
textfield.value = textfield.value.replace(regex, "");
}
}
</script>
Thanks for your time guys!
You can build your regex with multiple | (pipe) separated words:
textfield.value = textfield.value.replace(/badword1|badword2|badwordn/gi , "" );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With