Skip to content

Instantly share code, notes, and snippets.

@flacodirt
Created June 24, 2013 14:44
Show Gist options
  • Save flacodirt/5850564 to your computer and use it in GitHub Desktop.
Save flacodirt/5850564 to your computer and use it in GitHub Desktop.
Trigger only on word characters, backspace or delete and an entry size of at least 3 characters
// Search
$('#categoryFilter').on('keyup', function(event) {
var searchText = $(this).val();
var c = String.fromCharCode(event.keyCode);
var isWordCharacter = c.match(/\w/);
var isBackspaceOrDelete = (event.keyCode == 8 || event.keyCode == 46);
// Trigger only on word characters, backspace or delete and an entry size of at least 3 characters
if((isWordCharacter || isBackspaceOrDelete) && searchText.length > 2) {
console.debug('Searching for ' + searchText);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment