?
Solved

regex and uk pound sign

Posted on 2005-04-19
4
Medium Priority
?
1,289 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:joegass
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
inq123 earned 1000 total points
ID: 13817469
Hi joegass,
> alert(String("£5000").match(/^£[\d,]+$/));

It worked just as intended.  Sounds like it's a problem with your OS to display £ sign in the alert window 'cause £ sign displayed in my alert (it displays "£5000").  If you worry if the matching was correctly done, you can further confirm by:

<script>
if(String("£5000").match(/^£[\d,]+$/)) alert("matched!");
else alert("unmatched!");
</script>

and it'll return "matched!"

Cheers!
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 13818297
> 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,]+$/)
0
 
LVL 2

Author Comment

by:joegass
ID: 13822635
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
0
 
LVL 2

Author Comment

by:joegass
ID: 13825225
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question