Welcome Guest, Not a member yet? Register   Sign In
Currency & Form_Validation
#1

[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?
#2

[eluser]InsiteFX[/eluser]
PHP - money_format
#3

[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...
#4

[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>
#5

[eluser]InsiteFX[/eluser]
Code:
if (preg_match('/^\s*[$]?\s*((\d+)|(\d{1,3}(\,\d{3})+))(\.\d{2})?\s*$/', $value))
{
    # value match
}
else
{
    # Match value failed
}




Theme © iAndrew 2016 - Forum software by © MyBB