I need to be able to search for the first name OR possible middle name and last name of a user and have it pop up in the search results. If my user in a test case is "Alicia Henderson", currently with the following code, I can grab anything from the letter A onward (i.e. Alic, Alicia Hen). However, I would like to be able to type in "H" and get Alicia Henderson (and all other cases in any other word in that may be in the users name. Similar to how Facebook, Twitter, and many other fantastic search engines have. Thanks in advance!
$("input[name='search_users']").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = "^" + $(this).val(), itemsFound = 0;
// Loop through each user
$(".send_to .messages .message_username").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).parent().css("display","none");
// Show the list user if the phrase matches and increase the count by 1
} else {
$(this).parent().show();
itemsFound++;
}
});
});