php
Validate a number using filter_var() method in PHP
If you want to validate a number in PHP you can use the filter_var() method and pass value and FILTER_VALIDATE_INT as parameters.
<?php
$value = 500;
if (!filter_var($value, FILTER_VALIDATE_INT) === false) {
echo("Value is valid");
} else {
echo("Value is invalid");
}
// -> Value is valid
?>
Was this helpful?
Similar Posts
- Validate IP address using filter_var() method PHP
- PHP program to find the number of days between two dates
- Send POST request without using curl using PHP 5+
- Convert characters to lowercase using strtolower() function in PHP
- Calculate length of a string using strlen() function in php
- Connect Mysql and PHP using mysqli
- Get last insert id in db using PHP