Jump to content

Preventing floats/fractions numbers


bachx

Recommended Posts

I've been trying to check for the number types entered by the user in case they're floats or not with no luck. I don't want the user for example to be able to enter 0.6 or .9, only real numbers should be allowed. I've tried is_float(), is_int() and is_real() with no luck, they either allow all numbers or pervent all. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/60068-preventing-floatsfractions-numbers/
Share on other sites

yeah, but fyi real numbers are 1,2,4.3,6.23423.2/4,6/23 non real numbers are 5sqrt(-1) 654sqrt(-1) or 654i  f

 

Any way try

 

<?php
$num = $_POST['num'];
$round = round($num);
if ($round == $num && is_finite($round)){
echo "Its a non decimal number containing a finite value have fun.";
else{
echo "Its in valid size";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.