How can I block further input in textarea using maxlength

Have you tried ​the maxlength attribute? That will block input once the character limit is reached. <textarea maxlength=”150″></textarea>​​​​​​​​​​​​​​​​​​​​​​​​​​ // Won’t work <input type=”text” maxlength=”150″ /> Edit It appears that maxlength for a textarea works in Chrome, but not in other browsers, my bad. Well, another approach would just be to monitor keydown events and if … Read more

JavaFX 2.2 TextField maxlength

This is a better way to do the job on a generic text field: public static void addTextLimiter(final TextField tf, final int maxLength) { tf.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(final ObservableValue<? extends String> ov, final String oldValue, final String newValue) { if (tf.getText().length() > maxLength) { String s = tf.getText().substring(0, maxLength); tf.setText(s); } } … Read more

How to set maxlength attribute on h:inputTextarea

HTML5 + JSF 2.2+ If you’re using HTML5 and JSF 2.2+, specify it as a passthrough attribute. <html … xmlns:a=”http://xmlns.jcp.org/jsf/passthrough”> <h:inputTextarea value=”#{bean.text}” a:maxlength=”2000″ /> HTML4 If you’re on HTML4, then it’s already not supported by HTML itself. It’s only supported on <input> element, not on <textarea> element. That’s also why there’s no such attribute on … Read more

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