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
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";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.