Jazzaferri
Well-Known Member
- Messages
- 2,631
- Location
- Victoria BC Canada
All greek to me
I guess most people reading this thread will understand why I've avoided regexs like the plague since I first heard about them over 15 years ago. I'm obviously a fake computer nerd.
^([€\$£])[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!).
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
Let's keep it simple!
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:
.*
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
Yes, but this should still fit in with the regex which allows both comma and period - provided where they go is not too specific.
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.
How about:
One mandatory field for currency.
One mandatory field for minimum price.
One optional field for maximum price.
.
