Jump to content

Recommended Posts

[code]
<?php
if (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]
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.
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.

Regards
Huggie
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.
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.