Specifying maxlength for multiline textbox

Use a regular expression validator instead. This will work on the client side using JavaScript, but also when JavaScript is disabled (as the length check will be performed on the server as well). The following example checks that the entered value is between 0 and 100 characters long: <asp:RegularExpressionValidator runat=”server” ID=”valInput” ControlToValidate=”txtInput” ValidationExpression=”^[\s\S]{0,100}$” ErrorMessage=”Please enter … Read more

Chrome counts characters wrong in textarea with maxlength attribute

Here’s how to get your javascript code to match the amount of characters the browser believes is in the textarea: http://jsfiddle.net/FjXgA/53/ $(function () { $(‘#test’).keyup(function () { var x = $(‘#test’).val(); var newLines = x.match(/(\r\n|\n|\r)/g); var addition = 0; if (newLines != null) { addition = newLines.length; } $(‘#length’).html(x.length + addition); }) }) Basically you … Read more