This topic is locked

Currency Validation

11/20/2006 10:11:18 PM
PHPRunner General questions
R
renegadekn author

I have a budget form set up and I would like the user to be able to enter a number as currency.

I'd like them to be able to enter 10000 or 10,000 or $10,000 or $10,000.00 for example without the user encountering an error. Right now when I enter $10,000 a message comes back and says that the field must be currency. Also what field type do I need it to be in my SQL Table?
Thanks,
-Rob

J
Jane 11/21/2006

Rob,
to enter these values you need to remove validation on the ADD/EDIT page.

Also I recommend you to set up this field as VARCHAR in your database.

R
renegadekn author 11/21/2006

Rob,

to enter these values you need to remove validation on the ADD/EDIT page.

Also I recommend you to set up this field as VARCHAR in your database.


I made those changes, most of the entries work, however if the user enters 10,000 instead of $10,000 the database only stores 10. VARCHAR can be totaled can't they?

I just need a way to account if the user enters the dollar amout with a comma, but without the dollarsign
Thanks,
-Rob

Alexey admin 11/22/2006

Rob,
I see what you saying.
Put this code into Before record added and Before record edited events to amend user-entered values

$values["Price"]=str_replace(array("\$"," ",","),array("","",""),$values["Price"]);



where Price is your actual field name.