Textarea limit characters for each row in javascript
<p>I am trying to limit the number of characters for each row in a textarea with javascript.
i have seen a few examples in here but doesn't do exactly what iam looking for.
i have wrote something which does it ok only if you add every time more than the limit.</p>

<p>With other words, i have a limit of 10 characters per row, if you always type at least 10 is working fine, but if you want to type 5 characters in first row and press enter to move to next line it wont let me it keeps redirecting me to first row and can't really figure it out how to overcome this.</p>

<p>Any help much appreciated.
Thanks</p>

<pre><code>&lt;textarea onchange="Validate(this)" onkeyup="Validate(this)" class="txtValidation15   textarea" id="txtpr1-0" cols="30" rows="20" name="txtpr1-0"&gt;&lt;/textarea&gt;

function Validate(control)
 {
    var limit = 10;
    var v = control.value; //var v = $(this).val();
    var vl = v.replace(/(\r\n|\n|\r)/gm,"").length;
    var newtext="";
    for (var i = 0; i &lt; v.length ; i = i + limit)
    {
        v = v.replace(/(\r\n|\n|\r)/gm,"");
        var n = v.substr(i,limit)
        if(i+limit &lt; v.length)
            n= n + '\n';

        newtext += n;
    }
    control.value = newtext;
}
</code></pre>
