I’m looking for a javascript that can limit the number of lines (by line I mean some text ended by user pressing enter on the keyboard) the user is able to enter in textarea. I’ve found some solutions but they simply don’t work or behave really weird. The best solution would be a jquery plugin that can do the work – something like CharLimit, but it should be able to limit text line count not character count.
Share
This might help (probably be best using jQuery, onDomReady and unobtrusively adding the keydown event to the textarea) but tested in IE7 and FF3:
*Edit – explanation: It catches the keypress if the ENTER key is pressed and just doesn’t add a new line if the lines in the textarea are the same number as the rows of the textarea. Else it increments the number of lines.
Edit #2: Considering people are still coming to this answer I thought I’d update it to handle paste, delete and cut, as best as I can.