javascript - Search for particular word using jQuery? -



javascript - Search for particular word using jQuery? -

i have script, let's users submit e message. want restrict users posting particular world, , 1 time word used, form cannot submitted (return false;) , alert outputted.

so how word check in jquery?

example:

1) desired world blocked: pizza

2) user puts word in textarea

3) user hits submit, used word beside other words form doesn't submit

if jquery cannot this, javascript can, i'd welcome javascript solution.

conceptually, when submit button pressed, contents of textarea. you'd search word pizza (one simple regular expression) , if found it, set cookie prohibits them submitting period of time (you decide how long time). then, on submit button, you'd check see if cookie exists , if does, you'd prohibit submit function. can either jquery or pure javascript/browser - that's personal preference.

here's little piece of code:

var o = document.getelementbyid("mytextarea"); if (o.value.search(/\bpizza\b/i) != -1) { alert("pizza not allowed"); // set cookie preventing future access }

javascript jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -