http://jsfiddle.net/nicktheandroid/U8T8p/4/
(function($) {
$('.filterinput').keyup(function() {
var filter = $(this).val();
if (filter.length > 2) {
// this finds all links in the list that contain the input,
// and hide the ones not containing the input while showing the ones that do
$(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
$(list).find("a:Contains(" + filter + ")").parent().slideDown();
} else {
$(list).find("li").slideDown();
}
return false;
})
}(jQuery));
This will filter the list based on if what you’ve typed matches ANY part of a word in the list. I’m trying to make it only match whole words, so it wont say it has a match until the full word is typed. Would Regex be best? Or? I need help, nothing I’ve tried has worked.
Something like this: http://jsfiddle.net/U8T8p/10/
The regex limits matches to those where the currently entered text starts at a word boundary. So, having typed ‘Stat’ you’d still match ‘United States’. You can make it match a full word by changing to
RegExp('\\b' + a + '\\b', i).