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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find US currency
Expression
^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$
Description
This re matches US currency format with lead dollar sign. Dollar value must have at least one digit and may or may not be comma separated. Cents value is optional.
Matches
$0.84 | $123458 | $1,234,567.89
Non-Matches
$12,3456.01 | 12345 | $1.234
Author Rating: The rating for this expression. Michael Ash
Source Michael Ash
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: phone number regex
Name: harsh
Date: 1/13/2012 6:04:55 AM
Comment:
please explain me this regular expression: 0[0-9]+ [1-9][0-9]{9}


Title: Great!
Name: Paul Mastin
Date: 3/1/2011 2:55:43 PM
Comment:
Thanks for your contribution! I don't use regex much, and so each time I needed to use it, I had to go back and nearly relearn it. This site is great!


Title: Great!
Name: Paul Mastin
Date: 3/1/2011 2:55:38 PM
Comment:
Thanks for your contribution! I don't use regex much, and so each time I needed to use it, I had to go back and nearly relearn it. This site is great!


Title: Actual working currency regex
Name: Darrell Thompson
Date: 1/6/2011 12:56:27 AM
Comment:
I have seen several published regex supposedly for handling US currency but, all were flawed, in that, they did not work, some allowing multiple decimals into the number or leading zeroes where none should be. I am not saying mine is not flawed and this is no challenge but, I believe it is error free. However, I do make liberal use of parenthesis to clearly delineate components. I wanted a regex to handle a U.S. currency amount of no more than 999 million with optional leading $, commas, trailing decimal places and leading zero for pennies only value. This will do that. ^ (\$?) ( ( ([1-9]) ([0-9]{0,2}) ((,?[0-9]{3}){0,2}) ) | ([0-9]?) ) ((\.[0-9]{2})?) $ ^ beginning of line (\$?) optional dollar sign - escaped for use as a literal ( beginning of OR condition ( ([1-9]) first digit must be greater than 0 ([0-9]{0,2} up to two more digits in first tri-number set ((,?[0-9]{3}){0,2}) comma is optional but, up to two more tri-number sets ) | OR condition ([0-9]?) optional single leading 0 before the decimal ) end of OR condition ((\.[0-9]{2})?) optional decimal point to two positions $ end of line Here is a sample preg-match use of the regex. However, note the triple escaped leading $ sign; preg-match rquired I do this but, I do not know why. Maybe someone out there can explain. The single escape is the regex standard. if ( ! preg_match( "/^(\\\$?)((([1-9])([0-9]{0,2})((,?[0-9]{3}){0,2}))|([0-9]?))((\.[0-9]{2})?)$/", $_POST["request"] ) ) { $status = false; }


Title: Actual working currency regex
Name: Darrell Thompson
Date: 1/5/2011 11:32:28 PM
Comment:
I have seen several published regex supposedly for handling US currency but, all were flawed, in that, they did not work, some allowing multiple decimals into the number or leading zeroes where none should be. I am not saying mine is not flawed and this is no challenge but, I believe it is error free. However, I do make liberal use of parenthesis to clearly delineate components. I wanted a regex to handle a U.S. currency amount of no more than 999 million with optional leading $, commas, trailing decimal places and leading zero for pennies only value. This will do that. ^ (\$?) ( ( ([1-9]) ([0-9]{0,2}) ((,?[0-9]{3}){0,2}) ) | ([0-9]?) ) ((\.[0-9]{2})?) $ ^ beginning of line (\$?) optional dollar sign - escaped for use as a literal ( beginning of OR condition ( ([1-9]) first digit must be greater than 0 ([0-9]{0,2} up to two more digits in first tri-number set ((,?[0-9]{3}){0,2}) comma is optional but, up to two more tri-number sets ) | OR condition ([0-9]?) optional single leading 0 before the decimal ) end of OR condition ((\.[0-9]{2})?) optional decimal point to two positions $ end of line Here is a sample preg-match use of the regex. However, note the triple escaped leading $ sign; preg-match rquired I do this but, I do not know why. Maybe someone out there can explain. The single escape is the regex standard. if ( ! preg_match( "/^(\\\$?)((([1-9])([0-9]{0,2})((,?[0-9]{3}){0,2}))|([0-9]?))((\.[0-9]{2})?)$/", $_POST["request"] ) ) { $status = false; }


Title: Actual working currency regex
Name: Darrell Thompson
Date: 1/5/2011 11:31:10 PM
Comment:
I have seen several published regex supposedly for handling US currency but, all were flawed, in that, they did not work, some allowing multiple decimals into the number or leading zeroes where none should be. I am not saying mine is not flawed and this is no challenge but, I believe it is error free. However, I do make liberal use of parenthesis to clearly delineate components. I wanted a regex to handle a U.S. currency amount of no more than 999 million with optional leading $, commas, trailing decimal places and leading zero for pennies only value. This will do that. ^ (\$?) ( ( ([1-9]) ([0-9]{0,2}) ((,?[0-9]{3}){0,2}) ) | ([0-9]?) ) ((\.[0-9]{2})?) $ ^ beginning of line (\$?) optional dollar sign - escaped for use as a literal ( beginning of OR condition ( ([1-9]) first digit must be greater than 0 ([0-9]{0,2} up to two more digits in first tri-number set ((,?[0-9]{3}){0,2}) comma is optional but, up to two more tri-number sets ) | OR condition ([0-9]?) optional single leading 0 before the decimal ) end of OR condition ((\.[0-9]{2})?) optional decimal point to two positions $ end of line Here is a sample preg-match use of the regex. However, note the triple escaped leading $ sign; preg-match rquired I do this but, I do not know why. Maybe someone out there can explain. The single escape is the regex standard. if ( ! preg_match( "/^(\\\$?)((([1-9])([0-9]{0,2})((,?[0-9]{3}){0,2}))|([0-9]?))((\.[0-9]{2})?)$/", $_POST["request"] ) ) { $status = false; }


Title: Russian Currency
Name: Gayatri Krishnan
Date: 5/15/2009 2:21:05 PM
Comment:
Hi Michael, Can you please provide me an expression which can validate string against russian currency format.


Title: US Currency
Name: Fortune Ngwenya
Date: 5/16/2008 7:37:57 AM
Comment:
PLZZZ. May you please help me with an extension of your regex ("^\$(?=\d|\.)((\d{1,3}(\,\d{3})*|(\d+)))?(\.\d{2})?$") ($0.84 | $123458 | $1,234,567.89) to include $1 234 567.89 [My Email: [email protected]]


Title: Nice!
Name: jab
Date: 7/6/2007 1:13:42 PM
Comment:
Greetings, nice regex. Could you modify it a bit? From ^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$ To ^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{1,})?$ Matches to the tenths digit only, eg '117.8' Kind regards, jab


Title: Nice exp
Name: Shinu Suresh
Date: 11/3/2006 8:01:15 AM
Comment:
Hi Michael, Can you please provide me an expression which can accept 00 only in the decimal place.


Title: Validate a text field
Name: Sobhan Maddineni
Date: 10/12/2006 3:37:21 PM
Comment:
Hi Michael,I need to validate a text field whether it is having atleast 2 alpha characters and maximum of 2 numbers. Can you help me on this ? My emailid: [email protected]


Title: Beautiful, thank you =)
Name: kaolin fire
Date: 3/16/2006 4:43:08 AM
Comment:
exactly what I was looking for. came here from your comment on http://regexadvice.com/forums/14884/ShowPost.aspx after a fair bit of otherwise fruitless searching. Mind was not up to constructing this from scratch at this hour.


Title: Re: Other currency symbol such as Php instead of $
Name: Michael Ash
Date: 4/29/2005 1:58:12 PM
Comment:
I'm not exactly sure what you mean in regards to Php but here is another regex that allow other currency symbols http://www.regexlib.com/REDetails.aspx?regexp_id=747


Title: Other currency symbol such as Php instead of $
Name: Liberateddreams
Date: 4/28/2005 1:52:44 PM
Comment:
hi.. it really works... but how can i use Php instead of dollar sign ($).. tnx.. jb


Title: Very Nice
Name: Paul Day
Date: 3/23/2005 8:34:28 AM
Comment:
Hi Michael, Great regex. Really saved me a load of time as I am terrible at them :)


Title: curreny expression
Name: Michael Ash
Date: 12/7/2004 5:31:27 PM
Comment:
^\$((\d{1,3}(\,\d{3})*|(\d+)))?(\.\d{2})$ will require cents but make dollars optional ^\$(?=\d|\.)((\d{1,3}(\,\d{3})*|(\d+)))?(\.\d{2})?$ will make dollars or cents optional but not both. However it requires lookahead support.


Title: curreny expression
Name: Phil Anderson
Date: 12/6/2004 4:16:08 PM
Comment:
Michael, I am looking for a regular expression that finds currency that will not require the leading dollar amount such as $.94 or$.25 as well as the others that this matches Thanks Phil


Title: Re: regular expression
Name: Michael Ash
Date: 9/17/2004 11:13:24 AM
Comment:
Parsing a name with a regex perfectly probably is not possible. A regex like http://www.regexlib.com/REDetails.aspx?regexp_id=486, which is geared for .Net, should do a fair job for most names in the format it's expecting but it won't be perfect.


Title: regular expression
Name: shella zulueta
Date: 9/16/2004 11:44:21 PM
Comment:
hi michael, i am looking for the regular expression for name.Can u help? shella


Title: Re: Currency Expression
Name: Cathy Carter
Date: 5/13/2004 9:15:52 AM
Comment:
Thanks, this works wonderfully!


Title: Very Nice Reg Ex
Name: Jeff Ellin
Date: 3/9/2004 8:19:46 PM
Comment:
My only suggestion would be to make the Dollar Sign optional (update below) if the value is being inputted by a user. ^(\$)?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$


Title: Re: Currency Expression
Name: Michael Ash
Date: 10/15/2003 9:30:07 AM
Comment:
Removing the \$ from the begining of this expression will accomplish that.


Title: Currency Expression
Name: Michael Ash
Date: 10/15/2003 7:49:15 AM
Comment:
Hello Michael, How u doin? i am looking for currency regular expression which can allow deical to 2 places without currency symbol. can u help? Yogi [email protected]


Title: Currency Expression
Name: Michael Ash
Date: 10/15/2003 7:42:20 AM
Comment:
Hello Michael, How u doin? i am looking for currency regular expression which can allow deical to 2 places without currency symbol. can u help? Yogi


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