I have a script, which let’s users submit e message. But I want to restrict some users from posting a particular world, and once that word is used, the form cannot be submitted (return false;) and an alert will be outputted.
So how would I do a word check in jQuery?
Example:
1) Desired world to be blocked: Pizza
2) User puts this word in the textarea
3) User hits submit, but he used this word beside his other words so form doesn’t submit
If jQuery cannot do this, but Javascript can, then I’d also welcome a Javascript solution.
Conceptually, when the submit button is pressed, you would get the contents of the textarea. You’d search it for the word pizza (one simple regular expression) and then if you found it, you would set a cookie that prohibits them from submitting for some period of time (you decide how long a time). Then, on the submit button, you’d check to see if the cookie exists and if it does, you’d prohibit the submit function. You can do this with either jQuery or pure javascript/browser – that’s a personal preference.
Here’s a little piece of the code: