View Full Version : Checking Input Number Values

09-15-2011, 03:30 PM
A common mistake when dealing with POST values of forms is not checking for all areas of problems. Here is a few to remember. I hope this is helpful.

When dealing with numbers only

if (isset($_POST['submit'])) {
$idnumber = $_POST['idnumber'];

if (!is_numeric($idnumber)) {
echo 'Error! this does not contain only numbers, please do not use letters or symbols.';

if ($idnumber < 0) {
echo 'Error! You cannot use negative numbers.';

if (strlen($idnumber) > 4) {
echo 'Error, you can only use 4 numbers.';

if ($idnumber == 0) {
echo 'Zero is not a number, please change it to a number.';

if ($idnumber == EMPTY) {
echo 'The field is blank, please go back and type in a value';