Miscellaneous Help - Regex

^([€\$£])[1-9]\d*(?:\.\d{2})?(?:\s?(?:to|-)\s?\1[1-9]\d*(?:\.\d{2})?)?$

Must start with a currency symbol followed by a number.
The number cannot start with 0.
If there is a decimal point then then it must be followed by exactly 2 digits.
This is optionally followed by a range specification, another currency symbol and number.
A range specification is an optional whitespace character followed by either "-" or "to" then again an optional whitespace character.
The 2 currency symbols must be the same

The following pass:

$10
£10.10
£10-£50
$10 - $50
$10 -$50.00

The following fail:

$10-£20 - currency symbols don't match
£10.1-£20 - only 1 digit after decimal point
$10 $20 - no range specification
$10 -$20 - too much whitespace*

*but the forum software took most of them out again
 
Last edited:
^([€\$£])[1-9]\d*(?:\.\d{2})?(?:\s?(?:to|-)\s?\1[1-9]\d*(?:\.\d{2})?)?$

If you look at Jeanette's post where she quotes the existing Regex it allows commas for delimiting thousands which this one doesn't. Also I think the second currency symbol should be optional (but you're right that mine doesn't enforce that they are the same and allows extra whitespace - I'm not sure how Draconian we want to be about that!).
 
If you look at Jeanette's post where she quotes the existing Regex it allows commas for delimiting thousands which this one doesn't. Also I think the second currency symbol should be optional (but you're right that mine doesn't enforce that they are the same and allows extra whitespace - I'm not sure how Draconian we want to be about that!).

I didn't notice the requirement for commas or omitting the second currency symbol. Anyhow, it's free. Take it or leave it. I'm not offering a support contract.
 
I don't know whether a UK website wishes to pander to exotic European tastes in these post-Brexit times, but I would like to point out that the use of a dot for the decimal point is a UK/US convention, and that strange foreign people use the comma for this, and a space or a period to mark thousands. Also, some people use "EUR" for Euro.

For example, the Amazon France website uses "EUR" followed by a space rather than "€" and uses a space for the thousands.
EUR 2 359,67

Amazon Germany and Amazon Italy use a period for the thousands
EUR 2.359,67
 
I don't know whether a UK website wishes to pander to exotic European tastes in these post-Brexit times, but I would like to point out that the use of a dot for the decimal point is a UK/US convention, and that strange foreign people use the comma for this, and a space or a period to mark thousands. Also, some people use "EUR" for Euro.

For example, the Amazon France website uses "EUR" followed by a space rather than "€" and uses a space for the thousands.
EUR 2 359,67

Amazon Germany and Amazon Italy use a period for the thousands
EUR 2.359,67

That's why I'm not offering a support contract.
 
I agree. That's the point. Once we start trying to specify how people should write prices and price ranges in an international context we quickly get into enormous complications. It has taken days to get a solution which only works in the UK and the USA. Which is why my solution is:

.*


So you've added extra requirements beyond those stated and then proposed a solution that doesn't even cover the original ones. I wish I could get away with that at work.
 
For example, the Amazon France website uses "EUR" followed by a space rather than "€" and uses a space for the thousands.
EUR 2 359,67

One suggestion that would overcome this is to take the currencly symbols out of the filed, and have in their own filed as radio buttons or dropdown selector.

Currently we chose £ $ and € as those are the currencies of most members. Of course we could easily add Canadian and Australian etc and I think that is more practical with a separate currency field. I think most people are using paypal, so in the end their currency will be converted during the transaction.

Amazon Germany and Amazon Italy use a period for the thousands
EUR 2.359,67

Yes, but this should still fit in with the regex which allows both comma and period - provided where they go is not too specific.
 
How about:

One mandatory field for currency.
One mandatory field for minimum price.
One optional field for maximum price.

Use the same Regex for the two price fields. This could be as simple as numeric characters only.
 
The Regex you're using already is very specific about where the commas and period go - commas for thousands separation only and period for decimal separator only.

OK, well maybe that specificness is not too important for our needs.
 
How about:

One mandatory field for currency.
One mandatory field for minimum price.
One optional field for maximum price.
.

I considered this, but for most sales there is only one price.

The range of price is only needed for a listing of multiple sales.

I think it could work very well, but does involve some extra wording.

  • Price (if only one item) - required
  • Other price for range (if multiple items) - optional.

I'm going to leave this up to Jeanette anyway as these things make my brain hurt.
 

Similar threads... or are they? Maybe not but they could be worth reading anyway 😀

Social

New! Social Feeds

Look out for the navigation icon:

Follow CafeSaxophone

Latest Song of the Month

Trending

Forum statistics

Topics
32,083
Messages
578,871
Members
8,140
Latest member
AnnaR
Back
Top Bottom