javascript - Check whether a word is in a text box regardless of case -


i trying figure out whether text box has given word, regardless of case. example, how can determine whether given text box, #textbox, has word "hello" in it?

var specialwords = ['hello','hello','hello']; //special words here  $('#textbox').keydown(function() {     var text = $(this).val();     text = text.split(" ");     var newtext = "";     for(var = 0; < text.length; i++){         // code check words     }     $("#check").html(newtext); }); 

the easiest way check whether text box has given word, irrespective of case, convert text box lowercase, split spaces , find indexof word.

var word = "hello".tolowercase();    // make sure word lowercase  $("#textbox").keydown(function () {     var text = $(this).val().tolowercase().split(" ");     if (text.indexof(word) > -1) {         //     } else {         // word not in text box     } }) 

if want check array of words, specialwords, wrap if block in loop. o(n²) complexity, should fine, long input isn't extremely long1.

1we're talking thousands upon thousands of words long matter.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -