regex and uk pound sign

Posted on 2005-04-19
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"

returns null

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

Question by:joegass
    LVL 8

    Accepted Solution

    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:

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

    and it'll return "matched!"

    LVL 30

    Expert Comment

    > 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?
    LVL 2

    Author Comment

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

    var test ="£12345";

    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
    LVL 2

    Author Comment


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Article by: Matthew
    I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
    There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now