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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Currency
Expression
^(?!\u00a2) #Don't allow cent symbol \p{Sc}? #optional unicode currency symbols (?!0,?\d) #don't allow leading zero if 1 or more unit (\d{1,3} # 1 to 3 digits (\,\d{3})* # if the is a comma it must be followed by 3 digits |(\d+)) # more than 3 digit with no comma separator (\.\d{2})?$ # option cents
Description
This regex validates Currency. The base monetary unit (ex. US dollar) followed by option two digit cent denomination. Base unit can't have leading zero. Comma's are optional on base units. Note: Your regex engine must support the \p character class to use this. For example this will work in .net but not javascript which doesn't support \p Also the ¢ is removed from the match by force. Any other cent symbol would need to be added to the exclude to not match.
Matches
$1,501.13 | £215 | €4.93
Non-Matches
01.00 | $.00 | ¢50
Author Rating: The rating for this expression. Michael Ash
Source
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: thanks
Name: andy
Date: 11/5/2008 1:36:00 PM
Comment:
Great expression for all currencies. Thanks, just what I needed.


Title: thanks
Name: andy
Date: 11/5/2008 1:26:22 PM
Comment:
Great expression for all currencies. Thanks, just what I needed.


Title: thanks
Name: andy
Date: 11/5/2008 1:26:11 PM
Comment:
Great expression for all currencies. Thanks, just what I needed.


Title: re: Nice Pattern
Name: Michael Ash
Date: 3/2/2004 10:20:34 AM
Comment:
Thanks Yes the Sc is the unicode currency property. The negative lookahead is to remove the unicode character(00a2) for the cent (¢) symbol, which is part of the currency group, to avoid patterns like ¢10.00 matching.


Title: Nice Pattern
Name: Darren Neimke
Date: 3/2/2004 6:19:47 AM
Comment:
Michael, what's the negative lookahead character at the beginning: (?!\u00a2)? Also interesting to see the Unicode Property matching via the \p{Sc} notation... Sc represents "Currency" I presume?


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