php whitelist form validation??

Reply

Join Date: Jul 2007
Posts: 36
Reputation: kodiak is an unknown quantity at this point 
Solved Threads: 0
kodiak's Avatar
kodiak kodiak is offline Offline
Light Poster

php whitelist form validation??

 
0
  #1
Jul 17th, 2007
Hi!!!

I need to check a form for illegal characters through a whitelist(list of allowed characters) with php. A function that could do this for me would be helpful...I can't find one on google...

I really have no idea how to do this....


thanks!!!!
~Kodiak
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: php whitelist form validation??

 
0
  #2
Jul 17th, 2007
preg_match();

You'll need to know regular expressions to use it.
Last edited by stymiee; Jul 17th, 2007 at 6:53 pm.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,481
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: php whitelist form validation??

 
0
  #3
Jul 17th, 2007
If the whitelist is entirely comprised of single characters, you can probably use
  1. preg_replace( "[^#$%]", "", $stringToFilter );
to replace any occurrence of "#","$",or "%" with an empty string. Just put whatever characters you need to strip in there. If it's not a simple single character situation (i.e. you need to strip something like "<p>") then you'll have to go deeper into regex land to get there.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,481
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: php whitelist form validation??

 
0
  #4
Jul 17th, 2007
Originally Posted by Ezzaral View Post
If the whitelist is entirely comprised of single characters, you can probably use
  1. preg_replace( "[^#$%]", "", $stringToFilter );
to replace any occurrence of "#","$",or "%" with an empty string. Just put whatever characters you need to strip in there. If it's not a simple single character situation (i.e. you need to strip something like "<p>") then you'll have to go deeper into regex land to get there.
Actually, sorry, that pattern is bad, use this instead
  1. preg_replace( "/[#$%]/", "", $stringToFilter );
(It was too late to edit the other post)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 36
Reputation: kodiak is an unknown quantity at this point 
Solved Threads: 0
kodiak's Avatar
kodiak kodiak is offline Offline
Light Poster

Re: php whitelist form validation??

 
0
  #5
Jul 17th, 2007
isn't there a way to make characters that are allowed(whitelist)
instead of characters that aren't allowed(blacklist)??
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: php whitelist form validation??

 
0
  #6
Jul 18th, 2007
Sure, you can regular expressions to look for anything you want.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 160
Reputation: w_3rabi is an unknown quantity at this point 
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: php whitelist form validation??

 
0
  #7
Jul 18th, 2007
  1. preg_replace( "/[^a-zA-Z0-9_]/", "", $stringToFilter );
i guess this could work for your case
replacing everything that is not char. or digit with whitespace
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,481
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: php whitelist form validation??

 
0
  #8
Jul 18th, 2007
Originally Posted by w_3rabi View Post
  1. preg_replace( "/[^a-zA-Z0-9_]/", "", $stringToFilter );
i guess this could work for your case
replacing everything that is not char. or digit with whitespace
That was what I was getting at, but I see I dropped the "^" when I retyped my earlier expression. It should work fine as a single character mask.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 160
Reputation: w_3rabi is an unknown quantity at this point 
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: php whitelist form validation??

 
0
  #9
Jul 18th, 2007
well what u did was the black list thing
and what i did is white one
it may look the same
but it is not!
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,481
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: php whitelist form validation??

 
0
  #10
Jul 18th, 2007
Originally Posted by w_3rabi View Post
well what u did was the black list thing
and what i did is white one
it may look the same
but it is not!
Yes, I got it turned around, which I mentioned previously

Anyway, it does not matter. I posted to support that what you posted should work for him, he just needs to tune the pattern to include his acceptable characters
Last edited by Ezzaral; Jul 18th, 2007 at 1:19 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC