Page 1 of 1

very simple question

Posted: Sat May 04, 2002 12:09 pm
by hob_goblin
on my tagboard alot of people think its funny to post blank messages..

i figured out how to prevent them from making blank messages, but i can't figure out how to stop them from posting messages with only " " spaces..

i want to make it so if the name is less than three characters it wont post, same with the message

what are the wild cards to do this?

if($var <= "whatgoeshere"){

Posted: Sat May 04, 2002 12:12 pm
by Bart
The strlen() function can find out the Strings Length, so something like so should work:

Code: Select all

if (strlen($var) < 3) &#123; // Post error message or something &#125;

Posted: Sat May 04, 2002 1:56 pm
by pozytron
You might want to make it check for spaces as well as for string length. To do that, here's an example:

Code: Select all

if (strlen(str_replace(" ","",$var)) < 3) &#123;
// Post error message or something
&#125;
This code simply tests the length of the string when there aren't any spaces. You could use trim() or chop() or something of the like, but then someone could just type "x x" and easily bypass the validation. The above method actually works pretty well.
Cheers

Posted: Sat May 04, 2002 5:11 pm
by hob_goblin
thanks alot guys..it worked well :D

what about this easy solution

Posted: Fri May 10, 2002 7:04 am
by dethron
Hi Guys,

Why we don't use

Code: Select all

if($var)&#123; 
           echo "Text Here";
           &#125; 
     else&#123; 
           echo "Fill all fields";
           &#125;
If $var is posted, then execute queries or display outputs, else just type an error messages or redirect another file :)

I think it will work too, am i right?

Posted: Fri May 10, 2002 11:05 am
by dusty
nope! spaces would make $var true, but it'd still be a blank message.