Checking for a number range : intval « Data Type « PHP






Checking for a number range

 
if ($_POST['age'] != strval(intval($_POST['age']))) {
    $errors[] = "Your age must be a number.";
} elseif (($_POST['age'] < 18) || ($_POST['age'] > 65)) {
    $errors[] = "Your age must be at least 18 and no more than 65.";
}
  
  








Related examples in the same category

1.intval() function: pass a second parameter that specifies the base for the conversion
2.intval() function: pass a second parameter that specifies the base to use for the conversion.