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").matc h(/^£[\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
the variable itm holds "£500"
if I alert it it definitely says "£500"
itm.match(/^£[\d,]+$/)
returns null
but
alert(String("£5000").matc
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
Not working on live box :(
https://www.experts-exchange.com/questions/21395866/document-write-and-including-js.html
https://www.experts-exchange.com/questions/21395866/document-write-and-including-js.html
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,]+