Regex to validate European Style currency


I am using Breezing Forms for Joomla where I am trying to validate a field whose value should be in european style currency.
Different from American or UK standard where the "," (comma) separates thousands and "." (full-stop) separates the cents/pence, the European standard uses the opposite system using "." to separate the thousands and "," to separate the coins. So acceptable values would look like: 1.400.000,55

In any case there is an in-built validation script in Breezing Forms which checks if dollar amounts are correct and accepts values formatted like:
(some examples)

The script is:
function ff_dollaramount2dp(element, message)
    var ex  = /^\d+$|^\d+\.\d{2}$/;
    if (!ex.test(element.value)) {
        if (message=='') message =" must be a number with two decimal places.\n";
        return message;
    } // if
    return '';
} // ff_dollaramount2dp

Open in new window

How do I modify this script or just the regex in the script to suit the European standard?

thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

var ex  = /^\d{1,3}(\.\d{3})*(,\d{2})?$/;
By the way, that code you posted does not seem to support commas in the amounts, just digits and an optional period with two cents digits.

If you really need to support commas, then you can use ozo's regexp above.  Otherwise, just replace the "\." with a "," (without the quotes, of course) in the original regexp.

badwolfffAuthor Commented:
Perfect, works.
There is just one problem.
If I enter a long number like 2400 or 2400,25 (which are also a valid euro amounts) it doesn't work.
Could you please suggest the adjustment?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.