Limit number of characters per line jQuery

Asked

Viewed 755 times

1

I have some fields textarea and I want to limit the number of characters per line using jQuery.

I don’t have code to handle Laerte yet, I insert it into the database with php and display it in html with php nl2br to break the line. I need to limit and do not know how to do, when the user type an amount of characters that exceeds the width of the div the text continues out of the div because there was no line break. I’m not in the with problem in the personal textarea, I’m time to pull from the bank, I have no problems with the amount of characters and yes with the amount of characters without giving a space getting a huge word. -

  • sets a maxlength in textarea and puts a max-width and maxheight in css

  • Already tried, pop the div and have some browsers who do not obey the maxlenght command.

  • You can add the code to the question?

  • You want to do a word wrap?

  • which browser you tested ? http://caniuse.com/#feat=maxlength

  • I don’t have code to handle Laerte yet, I insert it into the database with php and display it in html with php nl2br to break the line. I need to limit and do not know how to do, when the user type an amount of characters that exceeds the width of the div the text continues out of the div because it did not have a line break. I’m not in trouble with the personal textarea, I’m in the bank pull time, I have no problem with the amount of characters but with the number of characters without giving a space getting a huge word.

  • Maybe you can handle this directly in html using the wrap="on" property in your text area example link https://jsfiddle.net/r63sfc4o/

Show 2 more comments

1 answer

2

Try it like this:

textarea {
  word-wrap: break-word;
  max-width: 200px;
  max-height: 100px;
  min-width: 200px;
  min-height: 100px;
  resize: none;
}
<textarea maxlength="255"></textarea>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.