Title |
Test
Find
Pattern Title
|
Expression |
^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$ |
Description |
This expression will validate for US Currency with a wide range of input. Using other exps found on this site, I built this one to fix 2 main problems I was finding:
1-a space or blank entry is non-matching
2-use of .9 in place of .90 will match (this is for those people like me who hate to type and if I put .9 I mean .90
Hope this helps others save a little time. I feel I was pretty thorough in testing, but if you find something wrong, please post it. -Thanks |
Matches |
$1.99 | 1.99 | .99 |
Non-Matches |
$10.999 | 100,00.99 | blank |
Author |
Rating:
Not yet rated.
Kirk Fuller
|
Source |
Used bits of other exps found on this site to build this one |
Your Rating |
|
Title: Comma use
Name: Sly
Date: 8/26/2010 1:36:09 PM
Comment:
Hi Kirk,
I was not sure if the expression is intended to match 100,100
Thanks
Title: Negative Values
Name: Kirk Fuller
Date: 1/3/2006 11:42:13 AM
Comment:
Good thought to have negative inputs, this should do it....
^\-?\$?\-?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$
The change: Added a \-? before and after the \$?
This will allow you to input:
-1.00
-$1.00
$-1.00
You can remove the \-? before or after the $ depending on your design.
Title: allow for negative currency amounts?
Name: John
Date: 1/2/2006 4:30:22 PM
Comment:
Hi Kirk, thanks for posting this expression. I'm trying to incorporate it but I do want to allow my users to match on a negative currency amount. Is there something I can add to extend your expression? I'd like to match: ($2.00) or -2.00, -2, etc.