Can someone help me with this code I found?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fungku
Forum Newbie
Posts: 5
Joined: Wed Dec 31, 2003 11:59 pm

Can someone help me with this code I found?

Post by fungku »

Code: Select all

function validate_input($input, $allowspaces = 0)
 {
	$check = ($allowspaces==0)?"^([a-zA-Z0-9\-\._])*$":"^([a-zA-Z0-9\-\._ ])*$";
	if (!eregi($check, $input))
	 {
		return 0;
	}
	else return 1;
 }
I want to add an option like $allowspaces, like $allowpunctuation that would allow punctuation and line breaks and stuff. I am writing a review script and I need to check to make sure the review itself is safe, but this function doesn't work. It works fine for the titles and stuff.

How can I add another option to allow the following characters: . / ! ? $ * - [ ] ( ) ' " ; : ,

But still be safe?

Thanks if you can help me :)
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

First thing to do would be how to write a regular expression that would match those characters. Then you could edit the function.
Post Reply