Ninjakreborn Posted February 6, 2007 Share Posted February 6, 2007 This whole time I thought it did, the client said he could still enter letter values. I did that, it wasn't working for some reasons letter's are still going through. What is a good way to make 100% sure the value is a number. Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/ Share on other sites More sharing options...
jimmi8 Posted February 6, 2007 Share Posted February 6, 2007 wow, really? You could always use a regular expression i suppose but is_numeric should work shouldnt it. R u sure the codes right? Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178269 Share on other sites More sharing options...
Ninjakreborn Posted February 6, 2007 Author Share Posted February 6, 2007 Yes, it should work however, it's not. Generic tests (ALL numbers) works. Then when I retested, checked on php.net it'sn ot meant to be fullproof. It's not meant to work as a definitive. if you have number's, and hten some letter's it let's it got through depending on the combination. Anybody have something they use that is fullproof? Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178275 Share on other sites More sharing options...
jimmi8 Posted February 6, 2007 Share Posted February 6, 2007 well i didnt know that! like i said a reg exp is probably good here. Theres a good one at php.net on the is_numeric page in the comments bit: http://uk.php.net/is_numeric hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178283 Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 I would use if(!ereg("[0-9]+",$data)){ //send out an error Or shorten the regex more into "\d+". This will make sure that $data is any number of digits long. If you wanted to limit it you could use "[0-9]{min,max}". However, this won't allow for negatives vs. positives. But you could easily add that by putting a "-" in the very beginning of your character set, i.e. "[-0-9]+" should check all numbers as okay, whether or not they're negative. Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178285 Share on other sites More sharing options...
hvle Posted February 6, 2007 Share Posted February 6, 2007 // should be true var_dump(is_numeric('0123.45e052')); var_dump(is_numeric('0xFF')); // should be false var_dump(is_numeric('0123.45e')); var_dump(is_numeric('01e23.456')); output: bool(true) bool(true) bool(false) bool(false) as expected, I think is_numeric is fullproof Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178288 Share on other sites More sharing options...
jimmi8 Posted February 6, 2007 Share Posted February 6, 2007 yeah so it checks if a string has a numeric value in it...not that its just numbers only which i think is what the issue is here! Its kinda foolproof but doesnt check if the string is wholely numeric Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178314 Share on other sites More sharing options...
Jenk Posted February 6, 2007 Share Posted February 6, 2007 No, it accepts valid scientific notation's, as well as plain numbers. Use ctype_digit() for number checking, or a simple: if (strval($var) === strval(intval($var))) Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178319 Share on other sites More sharing options...
Ninjakreborn Posted February 6, 2007 Author Share Posted February 6, 2007 You were right originally, it ended up being a problem with the array from the very beginning. I am marking this as solved, thanks for the help. You helped me track down the problem. Quote Link to comment https://forums.phpfreaks.com/topic/37298-solved-is_numeric-not-working/#findComment-178324 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.