An HTML text input has an attribute called "maxlength", implemented by browsers, which if set blocks user input after a certain number of characters.
An HTML textarea element, on the other hand, does not have this attribute. My goal is to emulate the behavior of maxlength on an HTML textarea. Requirements:
- At a minimum, show (CSS change) that the user typed in too many characters.
- Ideally, block the user from typing more characters, as happens on an HTML input.
It is understood that server-side validation should check the length again. Here I am focusing on the client-side part only.
My question is: what is the cleanest client-side way of emulating maxlength on an HTML textarea? Ideally, point to a proven, open source, piece of JavaScript that you have used.