views:

22

answers:

1

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 for a onSubmit check too at this late hour ;-)

Does anybody know of a plugin / snippet that can do that?

Thanks!

+1  A: 

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++;
   }   
}
Jacob Relkin
That was quick - thank you!
Matt