0

I have array of keywords. How can I find if any of these keywords present in textarea? Is there any plugin or function to do that?

Thank you

Kelvin
  • 8,813
  • 11
  • 38
  • 36

2 Answers2

5
var words = $('#text').val().split(/\b[\s,\.-:;]*/);
var keywords = ['keyword1', 'keyword2'];

var isKeywordPresent = $.grep(keywords, function(keyword, index) {
    return $.inArray(keyword, words) > 0;
}).length > 0;
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • This solution should use return $.inArray(keyword, words) > -1; $.inArray will return 0 if the first word in words matches. – Hobhouse Jul 23 '10 at 06:22
-1

for some ideas @SO Find text string using JQuery?

Community
  • 1
  • 1
TigerTiger
  • 10,590
  • 15
  • 57
  • 72