Page 1 of 1

Can someone help me with this code I found?

Posted: Wed Jan 07, 2004 6:11 pm
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 :)

Posted: Wed Jan 07, 2004 9:29 pm
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.