Solved

Regular expression to checking ...?

Posted on 2008-06-24
4
214 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now