Solved

Regular expression to checking ...?

Posted on 2008-06-24
4
218 Views
Last Modified: 2008-06-25
Hello group,

How can I avoid users from entering some specific characters in Form entries? characters such as & ^ % # @ and so on?

I don't know that much about Regular Expression but will appreciate it if you pass me some links to learn how to use it in PHP.

Regards.
0
Comment
Question by:akohan
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
CurtinProp earned 150 total points
ID: 21862462


$banned = array("#","^","%");
$text = "This is 20% of the total #number of ^carrots";
$string = str_replace($banned, "", $text);
 
If you echo string it would display;
This is 20 of the total number of carrots
 
Now this is a simple approach, regular expressions would be the best sollution if it got more advanced. If your trying make your forms safe from XSS attacks or SQL injection i'd suggest using alternate frameworks to assist you.

Open in new window

0
 

Author Comment

by:akohan
ID: 21863119

Hi CurtinProp,

You did point to something I always think of. As matter of fact, I've started PHP just few months ago and not sure what XSS attaks are. Would you please give me direction toward this concept? Any online resource or book would be great.


Thanks.
0
 
LVL 2

Expert Comment

by:CurtinProp
ID: 21863158
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts.
http://en.wikipedia.org/wiki/Cross-site_scripting

For books I suggest;
http://www.amazon.com/Cross-Site-Scripting-Attacks-Exploits/dp/1597491543/ref=pd_bbs_sr_1/104-1412087-4929535?ie=UTF8&s=books&qid=1177355137&sr=1-1

This book was written by industry experts and is the best reference.

He also has a blog which I also read; www.jeremiahgrossman.blogspot.com/
0
 

Author Comment

by:akohan
ID: 21863546

Wow! thank you so much for the details.

Regards.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question