Currency & Form_Validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Currency & Form_Validation (/showthread.php?tid=51132) |
Currency & Form_Validation - El Forum - 04-22-2012 [eluser]theshiftexchange[/eluser] I've tried searching on these forums & googling with no luck: Does anyone have a _callback_function for currency form validation? Basically I want to allow: - $ (first symbol only, but NOT required) - number >= 0 (i.e. no negative) - optional decimial point - 0-2 decimal places (if decimial point was used) I'm NOT interested in allowing commas, such as "$1,249.50" - but that is a bonus if it accepts it. I'm thinking I could do a function to check for all this - but I'm guessing a Preg_check() would be better - I'm just not sure how to do it? Currency & Form_Validation - El Forum - 04-22-2012 [eluser]InsiteFX[/eluser] PHP - money_format Currency & Form_Validation - El Forum - 04-22-2012 [eluser]theshiftexchange[/eluser] sorry InsiteFX - that does not actually answer my question. That link allows for the formatting of a number into currency. I need to be able to validate a number to confirm it is a valid currency format... Currency & Form_Validation - El Forum - 04-22-2012 [eluser]cPage[/eluser] <a href="http://bytes.com/topic/php/answers/442087-clean-currency-input">http://bytes.com/topic/php/answers/442087-clean-currency-input</a> Currency & Form_Validation - El Forum - 04-22-2012 [eluser]InsiteFX[/eluser] Code: if (preg_match('/^\s*[$]?\s*((\d+)|(\d{1,3}(\,\d{3})+))(\.\d{2})?\s*$/', $value)) |