darkfreaks Posted April 14, 2009 Share Posted April 14, 2009 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" ??? Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/ Share on other sites More sharing options...
Mchl Posted April 14, 2009 Share Posted April 14, 2009 0.0 is a valid number. Try is_int Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809821 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 can you give me an example please ??? seems when i type is int() it returns true and doesn't work and when i do NOT is_int() it gives me "only numbers allowed" even when i type 12345 :-X Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809836 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 How are you using is_numeric? This returns true for me. if(is_numeric(0.0)) { echo "true"; } else { echo "false"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809845 Share on other sites More sharing options...
mrMarcus Posted April 14, 2009 Share Posted April 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809846 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 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 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 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809850 Share on other sites More sharing options...
mrMarcus Posted April 14, 2009 Share Posted April 14, 2009 <?php if(is_int($_POST[height)) { }?> check your round bracket by $_POST[height) Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809855 Share on other sites More sharing options...
mrMarcus Posted April 14, 2009 Share Posted April 14, 2009 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809856 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 not on my end sorry probably a typo copying it over and is there a better solution then is_int this is not going to work. :-X Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809857 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809876 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 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 ??? Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809886 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 if(!is_int_val($_POST[height)) { // If it IS NOT an integer } else { // If it IS an integer } Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809888 Share on other sites More sharing options...
Mchl Posted April 14, 2009 Share Posted April 14, 2009 Remember that all $_POST values are strings. That's why is_int() fails on this check. My bad. Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809940 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 It's better to use the function I gave you because it uses a variety of data type check to see what's what. Because you actually want a string that only has digits in it, or an (int) data type. Quote Link to comment https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.