Googling is driving me mad; all jQuery textarea counters I can find either count words, newlines or characters.
I would like to count a specific character as it gets entered in the textarea. More specifically I would like to 'live count' the amount of @ signs that get inserted before the backend processes it. Live is nicer (with the counter and all) but I'll settle开发者_JS百科 for a onSubmit check too at this late hour ;-)
Does anybody know of a plugin / snippet that can do that?
Thanks!
Simple:
var atCount = 0;
var i;
textarea.onkeyup = function() {
atCount = 0;
for(i = 0; i < this.value.length; i++) {
if(this.value.charAt(i) == '@')
atCount++;
}
}
精彩评论