tags:

views:

206

answers:

2

Hello,

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

A: 

for some ideas @SO Find text string using JQuery?

Wbdvlpr
+3  A: 
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
Thanks a lot darin!
Kelvin
This solution should use return $.inArray(keyword, words) > -1; $.inArray will return 0 if the first word in words matches.
Hobhouse