<textarea id="ta"></textarea> <script> document.getElementById('ta').onkeyup = function() { var expr = /[\n\r]/g, value = this.value; alert(value.length - (expr.test(value) ? value.match(expr).length : 0)); }; </script>