Link to home
Start Free TrialLog in
Avatar of joegass
joegass

asked on

regex and uk pound sign

I'm trying to use javascript to test for a currency string

the variable itm holds "£500"

if I alert it it definitely says "£500"

itm.match(/^£[\d,]+$/)
returns null

but
alert(String("£5000").match(/^£[\d,]+$/));
returns "?5000"

Am I seeing some sort of encoding problem?
The variable is being read from a html table cell and it's source was an xml doc

Thanks
ASKER CERTIFIED SOLUTION
Avatar of inq123
inq123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GrandSchtroumpf
GrandSchtroumpf

> if I alert it it definitely says "£500"
Try this to makes sure there is no extra spacing:
alert("x" + itm + "x");

> itm.match(/^£[\d,]+$/)
> returns null
What if you trim itm first?
itm.trim().match(/^£[\d,]+$/)
Avatar of joegass

ASKER

inq123 I think you are right
trying something simple like this #

var test ="£12345";
alert(test);

on the server displayed ?12345

So the root of my problem is that my regex patterns are having their £ signs converted to ? - which is going to screw up the patterns
Luckily for me this is a test box and the live one seems to be OK

GrandSchtroumpf - thanks for your suggestion