Validate an integer with PHP

Free Scripts :: PHP :: Validation :: Validate an integer with PHP

Author: Salman Javaid

Website: http://www.salman.be

  • Validate a number value with php.
  • How to validate an integer with php.
  • Validate a number value with php.

Function accepts a parameter and returns false if value is not an integer.
Function
function isValidInteger($string){
if(!preg_match("/^[0-9]+$/",$string)){
return false;
}
}
Calling The Function
$string=5;
if(isValidInteger($string)!==false){
echo 'Value is an integer';
}else{
echo 'Value is not an integer';
}
Output
Value is an integer

Comments

Binod Lamasl - July 31, 2011
how does the is_integer function works instead of

Leave a comment

Full Name*
Comments*
Security Code*

Our Partners

Getty Icons  Salman Creations
Free High Quality Images  Learn Free Languages 
Opal Hosting  R-Tech Solutions
  • Submit a Script

    Click here to submit your script.