<form>
<textarea id='test' maxlength='200'></textarea><br>
<span id='rest'></span>
</form>
$('#test').on('keydown', function(event) {
var MAXLEN = 200;
var str = $(this).val();
var newLines = str.split('\n').length-1;
var len = str.length+newLines*99;
if (event.which == 13) {
if (len > MAXLEN-100)
return false;
else
newLines++;
}
$(this).attr('maxlength', MAXLEN-newLines*99);
return true;
});
$('#test').on('paste', function(event) {
var MAXLEN = 200;
var str = $(this).val()+event.originalEvent.clipboardData.getData('Text');
var newLines = str.split('\n').length-1;
var len = str.length+newLines*99;
if (len > MAXLEN)
return false;
return true;
});
$('#test').on('keyup', function() {
$('#rest').text($(this).val().length+'/'+$(this).attr('maxlength'));
});