Ninjakreborn Posted September 25, 2006 Share Posted September 25, 2006 [code] <?phpif (isset($price)) { if (!is_numeric($price)) { $errorhandler .= "The Price value has to be Numbers only.<br />"; } }}?>[/code][b]Intended Code Function[/b][list][*]Check to see if they filled out the price field.[*]If they did make sure it was numeric value only.[*]If not return an error indicating so.[/list][b]Current Script Function[/b][list][*]Checks to see if they put in a price[*]Check to see if it's numeric only, but fails in it's purpose. It misses the $ symbol, so when someone puts in a price with a $ then it returns the value always to $0 instead. Also I have it automatically putting in a dollar sign on display, so I needed to keep them from it here.[/list] Quote Link to comment https://forums.phpfreaks.com/topic/22003-problem-with-is_numeric-or-i-am-using-it-wrong/ Share on other sites More sharing options...
wildteen88 Posted September 25, 2006 Share Posted September 25, 2006 You cannot add a dollar sign and pass that through the is_numeric function . is numeric only accepts numbers, optional decimal point, optional exponential part and few other number specific characters.First you'll wnat to loose the dollar sign and then pass it through the function and then add the dollar sign backin. Quote Link to comment https://forums.phpfreaks.com/topic/22003-problem-with-is_numeric-or-i-am-using-it-wrong/#findComment-98320 Share on other sites More sharing options...
HuggieBear Posted September 25, 2006 Share Posted September 25, 2006 I think this is a job for a Regular expression.Look at the manual for both [url=http://uk.php.net/manual/en/function.preg-match.php]preg_match[/url] and [url=http://uk.php.net/manual/en/function.preg-replace.php]preg_replac[/url]e.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22003-problem-with-is_numeric-or-i-am-using-it-wrong/#findComment-98324 Share on other sites More sharing options...
Ninjakreborn Posted September 25, 2006 Author Share Posted September 25, 2006 No I mean, I am adding hte dollar sign when the information is pulled from the database. I was hoping to use is_numeric to check and see if they put in a dollar sign, and return an error message. When I first tested it, with a dollar sign it returned the error, but now it's just changing it over to a $0 instead. Quote Link to comment https://forums.phpfreaks.com/topic/22003-problem-with-is_numeric-or-i-am-using-it-wrong/#findComment-98340 Share on other sites More sharing options...
HuggieBear Posted September 25, 2006 Share Posted September 25, 2006 Id try something like:[code]<?php$price = $_GET['price'];if (preg_match("/^\$/", $price)){ echo "Please remove the $ from the price field<br>\n";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22003-problem-with-is_numeric-or-i-am-using-it-wrong/#findComment-98388 Share on other sites More sharing options...
Ninjakreborn Posted September 25, 2006 Author Share Posted September 25, 2006 ah thanks, I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/22003-problem-with-is_numeric-or-i-am-using-it-wrong/#findComment-98457 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.