Reputation: 718
In a PHP application I want to validate the format for the entered amount in a form. The amount should be entered in german format, 1.001,00
for thousand and one. Formatting like dot ,comma and number only is allowed to enter?
Any help will be appreciated?
Upvotes: 2
Views: 223
Reputation: 3242
Simple Regexp validation in the model should suffice?
/[\d.](,\d\d)?$/
That will validate that only digits and periods are allowed, with a comma and two digits optionally at the end. It won't validate that the periods are correctly placed, but they are decorators rather than identifiers, the comma is the only important one in terms of positioning.
To turn this out into a float
in PHP I don't think Yii provides any locale dependant parsing code so it's probably a manual job.
Remove all periods, convert the comma to a period and pass through floatval()
?
Upvotes: 1