the text input only allows three words separated by spaces, and if it exceeds 3, the user can\'t input anymore, is this possible using jQuery? I can use keyup event to liste
EDIT: Something like this should do it (tested):
$('#myTextbox').keyup(function(e){
var wordArr = $(this).val().split(' ');
if(wordArr.length > 3 && e.keyCode == 32) {
var arrSlice = wordArr.slice(0,3);
var newStr = arrSlice.join(' ');
$(this).val(newStr);
}
});
If the user attempts to type in more than three words, the contents will be overwritten with only the first three words. This solution will show characters being removed as they are typed if three words are exceeded, thus providing a bit of feedback.
If that's not the desired behaviour, @Jataro's solution is the way to go.