Jump to content

Recommended Posts

okay so i have used is_numeric() to make sure everything entered is only numbers however i have a slight problem if i enter 0.0 it just strips the dot and acts like i entered a whole number. how would i make it detect dots and then echo out "you cannot enter dots"  ???

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/
Share on other sites

How are you using is_numeric?

 

This returns true for me.

 

<?php

if(is_numeric(0.0)) {
   echo "true";
} else {
   echo "false";
}

?>

that will because it is true .. is_numeric is not checking for integer values .. it's simply checking if the value/string in question is a number/numeric.

 

is_int() will check if the value/string is an integer and return true/false .. 0.0 will return false on and is_int() check.

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809846
Share on other sites

im doing something like :

<?php
if(!is_int($_POST['height)) { 
}?>

 

and:

<?php
if(is_int($_POST['height)) { 
}?>

 

o0ps yeah your right is_int() not numeric ;D

 

anyhow 0.0 returns false because of the dot right? thats what i dont want to allow. however if i type 12345 i still get  "numbers only allowed" which telling me its still returning false :-\

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809850
Share on other sites

im doing something like :

<?php
if(!is_int($_POST['height)) { 
}?>

 

and:

<?php
if(is_int($_POST['height)) { 
}?>

 

o0ps yeah your right is_int() not numeric ;D

 

anyhow 0.0 returns false because of the dot right? thats what i dont want to allow. however if i type 12345 i still get  "numbers only allowed" which telling me its still returning false :-\

typing 12345 will return true on an is_int() check .. typing '12345' will return false.  12345 cannot be treated as a string.  refer to my previous post though, and correct the syntax.
Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809856
Share on other sites

You're going to have to check multiple things.  Use this function:

 

function is_int_val($data) {
if (is_int($data) === true) return true;
elseif (is_string($data) === true && is_numeric($data) === true) {
   return (strpos($data, '.') === false);
}
   return false;
}

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809876
Share on other sites

that function is messing up my form it only returns "you are obese"

 

is there another way i could implement this ???

 

maybe instead of returning true or false to maybe echo "you cant enter dots"

 

i really dont understand the return part anyhow ???

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809886
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.