Solved

# Regular expression currency

Posted on 2006-05-10
1,430 Views
Hi
Has anyone got a regular expression that validates currency that starts with the currency symbol first.

i.e £10.99, \$10.99, €10.99 etc

the number before the . must be 2 digits i.e: 10, 05 etc and 2 digits after i.e 10.99 etc.

So what i'm looking for is something like:

£10.99
\$100.99
€05.99

I've looked around the web, but all I can find is either starting with 1 currency symbol only either £ or \$ etc, not a choice.

Regards
Caz

0
Question by:BeginningWebDesign

LVL 25

Accepted Solution

(£|\$|€)[0-9]{2,}[\.][0-9]{2}
0

LVL 25

Expert Comment

The currency symbols may give you problems though -- I've never used them in a regex before.

In which case, you will probably need to use a character value, such as:

\uhhhh

This will be the character with the hex code 0xhhhh
0

LVL 25

Expert Comment

..Yeah, you cannot use a dollar sign at least in a regex, that symbolises "end of line".
0

LVL 7

Expert Comment

try this...

[£\$€][\d+].\d{2}

you can put however many currency signs you want.  \d+ allows any number of digits preceding the the point the only 2 digits following the point.  You could also do
0

LVL 7

Expert Comment

whoops i should refresh before i post.......answers a plenty.

Steve
0

LVL 7

Expert Comment

I think you can escape it \\$ ???
0

LVL 25

Expert Comment

Most probably. :)
0

LVL 7

Assisted Solution

Just had a little play and this did the trick for me.....

[£\\$€]\d{1,4}\.\d{2}

Steve
0

Author Comment

Hi osiris247 and InteractiveMind

But i've came across 1 problems if I enter £1,000.00 it comes back incorrect format, is it possible to change (£|\$|€)[0-9]{2,}[\.][0-9]{2} so that it accepts £10.00, £05.00, £1,000.00, £10,000.00 etc.

No problem if it cannot be done, as i've awarded points as you both answered the question I asked, I did not think about the , in values of 1000 and greater.

Caz
0

LVL 7

Expert Comment

you will need to add an OR clause for the complete expression....

[£\\$€]((\d{1,4}\.\d{2})|(\d{1,4}\,\d{1,4}\.\d{2}))

Steve
0

LVL 25

Expert Comment

Try

[£\\$€](\d{2,3}[,]?)+
0

LVL 25

Expert Comment

Sorry, I mean

[£\\$€](\d{2,3}[,]?)+\.\d{2}
0

## Featured Post

Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…