Some things I'd note:
only want to allow A-Za-z0-9 spaces, commas, and curved brackets
But your pattern also has a hyphen in it
The problem is that the hyphen char has special meaning inside of square brackets which is to express a range of chars. (This is probably the source of your allowance for "bad" chars) Placing one at the end tells the regex engine you wish to have the hyphen char included in the char range.
Those things in mind, try this:
<?php
$allowedCharPattern = '/^[A-Z0-9 ,()-]+$/i';
if( preg_match( $allowedCharPattern, $_GET['l'] ) )
{
//all chars are good
}
else
{
//bad char detected
}
?>
Hello, I've got some user input going into file.php?l=
I only want to allow A-Za-z0-9 spaces, commas, and curved brackets,
and if anything else is there, give an error.
At the moment it does stop $ or ^ or & ...
but not *,
also it doesn't stop r% or "asa or a£a
which I would like it to.
Any help would be greatly appreciated, thanks.
$expr = '/^[^A-Za-z0-9()-, ]+$/';$p = preg_match($expr,stripslashes(urldecode($_GET['l'])));
if($p==0) {
//all is fine, go ahead
}
else {
//error, get out of there
}