how to check if PHP variable contains non-numbers?
If you mean that you only want a value to contain digits then you can use ctype_digit()
.
You can use is_numeric()
:
if ( is_numeric($_POST['foo']) ) {
$foo = $_POST['foo'];
} else {
// Error
}
This will check that the value is numerical, so it may contain something else than digits:
12
-12
12.1
But this will ensure that the value is a valid number.