Page 2 of 2

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 4:10 pm
by pickle
coooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool.

Yep, we do. It looks like the overflow property is what does it.

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 4:13 pm
by simonmlewis
The problem with that is that if someone were to enter:
this is cooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooollllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll and I love it so much.

What would happen to the rest of it on that line?

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 4:14 pm
by simonmlewis
interesting. That's it then. Will try again and with the 'hidden' overflow. Thanks...
ssssssooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much. :)

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 4:55 pm
by McInfo
If you want to reject inputs with long words, you can use this pattern:

Code: Select all

if (preg_match('/[^-; \n]{32}/', $subject) === 0) {
    // All words have reasonable lengths (in this case, fewer than 32 characters).
} else {
    // At least one word is too long.
}
Or you can break long words with wordwrap(), but that would mean accepting long words and users might be annoyed by a "feature" that modifies their input.

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 5:06 pm
by simonmlewis
Genius. This is precisley what I was after.

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 5:21 pm
by McInfo
I did a little more testing. Firefox only wraps on a few characters. So, I've changed the pattern in my previous post.

Re: Prevent Continuous characters on a form - can you?

Posted: Mon Apr 18, 2011 5:27 pm
by pickle
If users are entering information in a textarea, another thing you may want to look at is changing how wordwrapping is done right in the textbox. Setting "wrap" to "hard" might be beneficial to the user as what they see is what gets posted & shown back to them.

http://www.tizag.com/htmlT/htmltextarea.php

Re: Prevent Continuous characters on a form - can you?

Posted: Tue Apr 19, 2011 2:48 am
by darek
The only way that worked for me is this:

Code: Select all

preg_replace ('/(?<=s|>)([^"'s<>]{59,})(?=s|<)/e', 'substr(chunk_split("$1", 57, "- "), 0, -2)', $str); 
Where:
- 59 is "max length of single word"
- 57 is "max length of single word" - 2
- $str is input string

How it works? Basically, it cuts long words into pieces and adds "- " at the end of each piece, except last piece.

You can also use php wordwrap function, but it looks good ONLY if you using fixed width fonts, so in most cases you don't want to use it.

Re: Prevent Continuous characters on a form - can you?

Posted: Tue Apr 19, 2011 2:52 am
by simonmlewis
This looks to be a good method, but at the moment I am going to try the method from McInfo, where it just tells them off if they have entered too many non-stop characters. As I prefer to tell them it's wrong, rather than just ignore it and let them think it's wrong.

Or do you think I should just make them think it has passed through? Which is kind of what I am doing now - it just doesn't go live.

Re: Prevent Continuous characters on a form - can you?

Posted: Tue Apr 19, 2011 5:22 am
by darek
That's great question, simonmlewis. I see that you are one of these guys who like to think far beyond "here and now". Answering your question: I must admint, it's better idea to tell people they have entered too many characters in one word. You should use this method wherever you can.

But sometimes you already have database full of such too long words. That's where my method will work better.

Re: Prevent Continuous characters on a form - can you?

Posted: Tue Apr 19, 2011 5:32 am
by simonmlewis
True - but we moderate everything, so those long words never get thru. That's half the problem - when we moderate, and someone enters vastly long words, the moderation page goes 'wide'.

So this script will stop that properly, and keep the user informed.