Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Search box for blog entries

only want to allow alpha space and plus sign



10:02 am on Apr 12, 2007 (gmt 0)

5+ Year Member

Hi --
I am developing a blog system for myself. Right now all a user can do is see a list of blogs (as links which will display the whole blog) and enter a search term in a one-line form to find all blogs with that term.

I want to allow ONLY alpha chars (right now the search is not set up for boolean -- but eventually will be) spaces and a plus sign.

How would I go about this?-- I'm assuming it's pretty simple, but just haven't seen something I could use (that I completely understand-- I don't like employing code I don't fully understand!).

If they enter other stuff, I want to send them a page with a msg. that they screwed up, otherwise, I'll go ahead and do the search.

Thanks much.



10:16 am on Apr 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

do you want users not to enter illegal characters like +,&,# etc etc in search terms?

use regex for this e.g [a-zA-Z0-9] and no other symbol...

if you are afraid of query breaking then you can use mysql_real_escape_string() if your magic quotes are off...

but remember if you have programming related blog then you could use these symbols in your articles and this will prevent users to search for those articles...


10:39 am on Apr 12, 2007 (gmt 0)

5+ Year Member

Hi ph--

Right now the system only works with one search term (boolean not implemented yet -- so I don't know if I even need to let them use the plus sign.

Which means right now, I ONLY want alpha characters accepted -- anything else and they are out on their ears.

I think I don't know the term(s) to look for in PHP books to find the code that will look at what the form has sent to the PHP and check it for only alpha chars.

If you could tell me the function I need, I would much appreciate it.

I've set up this system and it it is working perfectly; I am now trying to implement security and can't believe this isn't a simple and common thing that I am trying to do.

Thanks again.


Featured Threads

Hot Threads This Week

Hot Threads This Month