PHP Regular Method to Judge Whether a Variable Is a Positive Integer

  • 2021-11-29 06:11:03
  • OfStack

Method 1 Judge positive integer


$keyword = '10'; // 0 1.1 1
if(preg_match("/^[1-9][0-9]*$/",$keyword)){
  echo " Is a positive integer! "; 
  exit();
}

Method 2 Judge positive integers


if ((floor($jp_total) - $jp_total) !==0){
  echo " Is not a positive integer ";
}else{
  echo " Is a positive integer ";
}

Method 3 Judge integers


if(!is_numeric($jp_total)||strpos($jp_total,".")!==false){
  echo " Is not an integer ";
}else{
  echo " Is an integer ";
}

Summarize


Related articles: