I am working on a simple custom content management system where a user can enter values into a form and have their new content update their website. The page that they can add content to is a pop-up window which has a width and height set to 400px.
The issue I am having is how to validate the maximum number of characters per word when a user types something into a textarea. ie. if someone types in: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa or a long url, the browser doesn't know where to break and thus creates a horizontal scrollbar and pushes around images.
Can someone point me to an example of where this has been done before? or have some pointers?
That's a tough situation to handle well automatically - you may have seen some occasional side scrolling here on the forums, which we moderators always edit by hand.
The following idea is untested, off the top of my head.
The split() method, with a space between the quotation marks, should generate an array where each of the individual words is a separate array element.
Then reverse sort the array by the length of its elements, so the longest word is in position 1. If the length of that first element is greater than your maximum, then send an alert to the user and refuse their input.
At least that seems to be one direction you could test out. Not sure how efficient it would be on a very long bit of text.