I have a textarea inside a form.
Before the form is submitted, the textarea is validated and checked so it is not empty, not over 2000 characters, not contain forbidden characters etc...
I am working on the last part of the validation, which would need the textarea to be compared to an array of "bad words".
This to help me maintain and keep a good "language" on my site.
I am not very good on js, so does anybody know of a way to compare each word of the textarea to the array of bad words?
Also, would this slow down the validation much? (the array contains at most 100 words).
Thanks
This code replaces bad words with *****
See in jsfiddle
If you wanted to check for the presence of "expletive1" and "expletive2" you'd do the following:
And you'd just add more words to the list in the same manner (expletive1|expletive2|expletive3|expletive4)
Keep in mind that to keep the words out of your app entirely you'll also need to do server-side filtering.
This will keep your code a bit neater, because you don't have to have 100 words in one regex match.
You can downvote me if you want, but maybe just don't make the clbuttic mistake of trying to filter in the first place :D