INPUT - Text Character Count - Roll Your Own

by bizamajig

HTML

<textarea id="myInput"></textarea> <br>
Counter: <span id="charCount"></span>

CSS

textarea { width:300px; height:200px; }

JavaScript

var input = $('#myInput'),
    count = $('#charCount'),
    limit = 10;

input.keyup(function() {
    
    var n = this.value.replace(/{|}/g, '').length;
    
    if ( n > limit ) {
        this.value = this.value.substr(0, this.value.length + limit - n);
        n = limit;
    }
    
    count.text( n );
    
}).triggerHandler('keyup');