/    Sign up×
Community /Pin to ProfileBookmark

Input Filter!

As most of you know I have been developing a shout box of sorts. I now want to do something that I don’t know how to do. I have noticed that if a user put’s in a bunch of spaces it will allow it to be submitted. I want to disallow the ability to enter blank messages. I want to set it up so you have to actually have text characters and not just spaces for it to be allowed. How can I do this? Thanks. ?

I thought I might post my code so you guys can help me better:

[code=php]Removed![/code]

Thanks again for the help. Please do not steal this script. You may ask for it but please don’t just take it. ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SamMar 06.2004 — this should be of use: http://www.php.net/manual/en/function.trim.php

what I would suggest would be to trim the string, then do a strlen check to make sure the message was longer than 1 character
Copy linkTweet thisAlerts:
@JickauthorMar 06.2004 — How would I do that? I understand what you mean and I went to that link you posted but I still really don't know how to do it! ?
Copy linkTweet thisAlerts:
@SamMar 06.2004 — [code=php]
if(strlen(trim($_POST['c']))>1)
{
//pass
}
else
{
//fail
}
[/code]
Copy linkTweet thisAlerts:
@JickauthorMar 06.2004 — Thank you very much... That works great. I now have one other question that has to do with the same script. How can I disallow the name to be "Administrator"? As you can see from my script above I have it checking each way manuelly but I want to make it so it will simply not allow the word admin in the name in any form, anyway so if the name has admin in it anywhere it will change it to guest. This is how I have it doing it now:[code=php]$name = str_replace("Administrator", "Guest", $name);
$name = str_replace("administrator", "Guest", $name);
$name = str_replace("Admin", "Guest", $name);
$name = str_replace("admin", "Guest", $name);[/code]
Copy linkTweet thisAlerts:
@SamMar 06.2004 — this might help:

http://us4.php.net/manual/en/function.preg-replace.php

It should get your 4 lines to 2 lines.

if you can't figure it out from the manual, try this:
[code=php]
$name = preg_replace("/admin/i","Guest",$name);
$name = preg_replace("/administrator/i","Guest",$name);
[/code]
×

Success!

Help @Jick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...