Forum Moderators: coopster
if (!preg_match('/[[:^digit:]]/', $_GET['number'])){
echo'You must not enter anything but a digit.';
} if (preg_match('/[[:^digit:]]/', $_GET['number'])) {
if(isset($_GET['number'])){
if(!preg_match('/[^0-9]+/', $_GET['number'])) {
$stripped = (int)$_GET['number'];
}else{
echo'You must not enter anything but a digit.';
}
}
if(isset($_GET['number'])&& (!preg_match('/[^0-9]+/', $_GET['number']))) {
$stripped = (int)$_GET['number'];
}else{
echo'You must not enter anything but a digit.';
}
}
I am trying to throw an error if the query string has ANYTHING but numbers present.
Does it make a difference which way round it's done?
From what I have understood doing similar in the past, this just forces the value held by the var to be a whole int.
The "stock" statement for validating input: accept what you want and throw everything else away. So just a preference, I'd do the positive match above.
Wait, no I wouldn't. I've be using PHP numeric functions. :-P