Regular expression currency

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

BeginningWebDesignAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
InteractiveMindConnect With a Mentor Commented:
(£|$|€)[0-9]{2,}[\.][0-9]{2}
0
 
InteractiveMindCommented:
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
 
InteractiveMindCommented:
..Yeah, you cannot use a dollar sign at least in a regex, that symbolises "end of line".
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
osiris247Commented:
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
 
osiris247Commented:
whoops i should refresh before i post.......answers a plenty.

Steve
0
 
osiris247Commented:
about the $ sign.

I think you can escape it \$ ???
0
 
InteractiveMindCommented:
Most probably. :)
0
 
osiris247Connect With a Mentor Commented:
Just had a little play and this did the trick for me.....

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

Steve
0
 
BeginningWebDesignAuthor Commented:
Hi osiris247 and InteractiveMind

Both your expressions work.

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
 
osiris247Commented:
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
 
InteractiveMindCommented:
Try

[£\$€](\d{2,3}[,]?)+
0
 
InteractiveMindCommented:
Sorry, I mean

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

From novice to tech pro — start learning today.