Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

admin sets prices. no commas

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

admin sets prices. no commas

Postby pugs421 » Fri Aug 01, 2003 8:47 am

When the prices are entered I will suggest the correct format next to the text box. ex. 150000. But if the user enters a comma it messes up the entry. How do I ensure that the prices can be entered correctly without a user making an error? Would I somehow remove the comma if the user entered one in, or is the another better way to handle prices that a user will enter.
New php-forum User
New php-forum User
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby Joel » Fri Aug 01, 2003 2:10 pm

You can remove common things what people are likely to put in first, and then if they still have foreign things then prompt them that there was an error by checking if the input is numeric.

Code: Select all
$search = array(',', '$', ' ');
$price = str_replace($search, '', $_POST['price']);
if (!is_numeric($price)) {
    //Print error and redisplay form
else {
    //Process price

New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.