This feels related to ellipsing labels. (not a duplicate of) You've got user-generated text of unknown length, and you don't want to display more than a certain amount.
The possible solutions
Just use the text as typed.
− Can lead to many errors.
Limit text length.
Force users to edit their text to be shorter.
+ Control, good looks
− More user effort. Missing some information.
Automatically truncate text. Use a simple script to delete excess text.
+ Only implementation effort, good looks.
− Missing some information. High chance of broken sentences. Unexpected endresult for user.
Automatically hide long text. Hide excess text behind a "show more" button. Either show inline or link to separate page.
+ Only implementation effort, good looks, all text.
− Will still give errors after interaction. Button will take up space.
(Personally, never automatically truncate text. Either let users edit, or have toggle to show/hide the remainder)
Decide what you want
You'll have to answer several questions, and then you have to decide whether you want to limit the text, automatically truncate, have a 'show more' button, or just let the text flow freely.
- Is the endresult aimed at consumers, b2b, or internal usage? The more public, the more looking good matters.
- How much do you trust your user? Would they just copy, paste, post, or are they going to think and edit?
- Is the text picked from a centralized database, so you should conform to that?
- How bad is the 'breaking'. Will text run over a flat colored background, or interfere with pictures? Will it just break the textbox or the whole layout?
- What does it cost you? Solving issues elegantly can take more time to develop.
- What does it cost them? How much extra time will it cost the end user to input new data? What's the potential CPU impact?
- How often do you expect the problem to occur?
Communicate the problem
No matter which solution you pick, you should tell users what's happening, and why.
Twitter won't allow me to post over 140 characters and it highlights excess in red. It also lists the exact amount of characters that I need to remove.
Facebook is more lenient. I can copy thousands of words in to a post and I can submit it, but it shows me an alternative format which might look better.
Similarly, you should inform the user of the expected amount of text. Tell them how many characters is good. Show when they're using too few, enough, almost too much, or too much. Tell them what problems might occur; the text will stretch the layout, it will run over images, it will get resized to a terribly small font. You needn't do all of these, just make sure users know what will happen.
Can you show a preview?
A picture says a thousand words.
If it's possible to show a WYSIWYG preview of the endresult, or at least a mockup of it, people will much better understand the issue, and they can at a glance decide if they're okay with it.
The above image is easier and faster to comprehend than just an error message:
using more than 5 lines will break the layout.
This leaves some wiggle room
You might want to have a roomy 32 pixels worth of whitespace around your text, but maybe your users will squeeze in just that one extra line at the bottom, keeping it in bounds, but with only 16 px of whitespace. This is something that's hard to decide ahead of time.
And word/line lengths aren't always easy to predict either. HTML still has heaps of problems with hyphenation, justification and kerning. Even the amount of characters doesn't translate to text length very well:
wwwwwwwwww - 10 w's
iiiiiiiiii - 10 i's
So sometimes you can fit 200 characters in, sometimes 220. Why not let the end user decide?