International currency formats
A recent post to the Regexlib reminded me that numbers are formatted differently in other countries. For Example :
345 987,246 fr_FR
345.987,246 de_DE
345,987.246 en_US
With that thought I modify one of my currency regex’s to be international capable. It is not internationally aware however. The point of doing this one is to allow easy modification to a locale specific format. The regex is posted on the regexlib here with embedded comments, but here is the expression
^(?!\u00a2)\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$
This regex will match each of the above numbers. It also allows for an optional leading currency symbol. However as I said it is not aware of the local so if you could use a currency sign of one local and number format of another and it would match. If you want to match this match only a certain local format you need to modify it to so. You can simply remove the separators you don’t want from the first character class and replace (?!\u00a2)\p{Sc} with your local’s currency symbol.
So ^\$?(?!0,?\d)(?:\d{1,3}(?:([,])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$
would be the US format
Note, while you could remove the unwanted decimal separator in the second character class it isn’t necessary since it can’t be the same as the first character group.