I want to incorporate some validation in the code that's processing some incoming form data. I need to make sure that a value coming in is either an integer or a decimal. Here's what I've got:
<?php
$number = 32,;
if(is_float($number)) {
echo "good";
}
elseif(is_int($number)) {
echo "good";
}
else {
echo "nope";
}
?>
This will work for either a regular number of a decimal, but...
...if the user makes the mistake of including a "," or anything bogus, rather than the script returning "nope," I get an error that says, "arse error: syntax error, unexpected ',' in C:\wamp64\www\adm\jquery.php on line 8." Line #8 being $number = 32,;
How can I trim or qualify the incoming value so if there's something ridiculous coming in, it won't even try to evaluate it? In other words, what can I do before I even attempt to discern whether the value is an integer to ensure that I'm not going to get an error before I even start?
Thanks!
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Fellow title is reserved for select members who demonstrate sustained contributions, industry leadership, and outstanding performance. We will announce the experts being inducted into the Experts Exchange Fellowship during the annual Expert Awards, but unlike other awards, Fellow is a lifelong status. This title may not be given every year if there are no obvious candidates.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.