I want to use jquery to limit the number of characters in an editable div (or form input).
How To: Use the Text Field. The Text field is one of the most generic and common data entry fields used to capture text type data—letters, numbers, and symbols. Text fields hold up to 255 characters in a single line.
You can specify a minimum length (in characters) for the entered value using the minlength attribute; similarly, use maxlength to set the maximum length of the entered value, in characters.
While you can't use CSS alone to do this, you can limit the amount of characters show using CSS as Darren has suggested. You need to set your text container to white-space: no-wrap, text-overflow: ellipsis, and overflow:hidden. Then simply set the size for your container.
The maxlength attribute allows you to specify a maximum number for characters for a text-based input field. This can help usability, such as when you need to limit the length of usernames or other types of input date.
make use of maxlength
in input
tag
<input type="text" maxlength="20" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With