Prevent Continuous characters on a form - can you?
Moderator: General Moderators
Re: Prevent Continuous characters on a form - can you?
coooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool.
Yep, we do. It looks like the overflow property is what does it.
Yep, we do. It looks like the overflow property is what does it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Prevent Continuous characters on a form - can you?
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?
this is cooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooollllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll and I love it so much.
What would happen to the rest of it on that line?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Prevent Continuous characters on a form - can you?
interesting. That's it then. Will try again and with the 'hidden' overflow. Thanks...
ssssssooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much.
ssssssooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Prevent Continuous characters on a form - can you?
If you want to reject inputs with long words, you can use this pattern:
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.
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.
}
Last edited by McInfo on Mon Apr 18, 2011 5:20 pm, edited 1 time in total.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Prevent Continuous characters on a form - can you?
Genius. This is precisley what I was after.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Prevent Continuous characters on a form - can you?
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?
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
http://www.tizag.com/htmlT/htmltextarea.php
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Prevent Continuous characters on a form - can you?
The only way that worked for me is this:
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.
Code: Select all
preg_replace ('/(?<=s|>)([^"'s<>]{59,})(?=s|<)/e', 'substr(chunk_split("$1", 57, "- "), 0, -2)', $str); - 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.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Prevent Continuous characters on a form - can you?
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Prevent Continuous characters on a form - can you?
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.
But sometimes you already have database full of such too long words. That's where my method will work better.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Prevent Continuous characters on a form - can you?
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.
So this script will stop that properly, and keep the user informed.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.