Thursday, February 08, 2007

Regular expressions for validating currency

Embedded as I am in globalizing applications I thought I would create this entry for future reference.

More than once I have to validate user input and more than once that input is a currency value. The currency symbols are not part of the expressions here.

For en-US or en-CA:

^(\d{1,3})(,\d{3})*(\.\d{2})?$

fr-CA currency formatting regular expression:

^(\d{1,3})(\s{1}\d{3})*(,\d{2})?$


Ttyl!

2 Comments:

Blogger Dave Field said...

Hi,

Found this post while searching for a currency regex to help with my cms project - and your's works instantly! Thanks!

6:39 AM  
Blogger Lizet Pena de Sola said...

Glad it helped. You're welcome...

9:05 AM  

Post a Comment

<< Home