I'm working on a PHP application. I need to validate that a string is useable as a currency value. I would like the following to validate:
$5.00
5
5.00
£5.00
I want the pattern to be liberal enough to accept a reasonable string. I would also like it to accept an currency symbol; however, to validate currency, it can be any character or characters because I'll ultimately store the value as a two decimal float. So, '$5.00' or 'USD 5.00' would become '5.00' when stored in the database. I'm currently using the following:
preg_match('/^[0-9]*\.?[0-9]+$/',$value)
It works for "5" or "5.00", but it does not account for the currency symbol. How do I adjust this to allow for the currency symbol?
Thank you!
EDIT: According to a comment below, it looks like my regex will allow too many decimals. Can you also help me sort out that issue?