RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

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
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

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.


Copyright © 2001-2018, RegexAdvice.com | ASP.NET Tutorials