Regular expression to checking ...?

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.
akohanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CurtinPropConnect With a Mentor Commented:


$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
 
akohanAuthor Commented:

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
 
CurtinPropCommented:
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
 
akohanAuthor Commented:

Wow! thank you so much for the details.

Regards.
0
All Courses

From novice to tech pro — start learning today.