I have this jsfiddle.
I have certain words which, when the user types them, it needs to be alerted to the user.
Right now when I type a certain line, for example, I love ants
it alerts me the full line I love ants
, but I want only ants
to be alerted to me. (In my example ants is a word need to be filtered. Refer to the jsfiddle.)
var filter = ['ants', 'words'],
reg = new RegExp("(" + filter.join("|") + ")", "g");
$('#texta').keyup(function(){
$("#dest").html(
$(this).val().replace(reg, "<mark>$1</mark>")
);
if(reg.test($(this).val())==true)
{
alert($(this).val());
}
});