Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    60
    Thanks
    65
    Thanked 0 Times in 0 Posts

    remove invisible char space in string

    Hi

    How do I remove an invisible space in a string that is caused by the regional number formatting settings.

    On the screen the text box value looks like 123 456 789.00000

    But when i get the the value with document.getElementById("testTXT").value it returns 123 456 789.00000 as a string;

    If I copy that space and paste it into notepad++ I get funny characters -- so it definitely is something

    But if I try replace the space it won't go and I think its becasue its an in visible char caused by the regional number formatting settings--- but which one?

    Code:
    var s = document.getelementId("testTXT").value;
    
    s = s.replace(" ",""); // wont remove it
     //or 
    s = s.replace(",",""); // wont remove it
    //or
     var d = new string(s);
    d.replace(" ",""); // wont remove it
    
    document.write(parseFloat("123 456 789.00000").toString() + "<br />"); //wont work either

    Thanks


    How do I remove this invisible char space
    Last edited by code-in-time; 05-29-2012 at 06:23 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Code:
    <input type = "text" id = "testTxt" value = "123 456 789.00000">
    
    <script type = "text/javascript">
    var x = document.getElementById("testTXT").value;
    x = x.replace(/[^\d\.]/gi,"")
    alert (x);
    
    </script>

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    code-in-time (05-29-2012)

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    60
    Thanks
    65
    Thanked 0 Times in 0 Posts
    thanks - what does that regex expression mean?


    does it mean only allow decimals and dots and remove everything else?
    Last edited by code-in-time; 05-29-2012 at 06:57 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by code-in-time View Post
    thanks - what does that regex expression mean?


    does it mean only allow decimals and dots and remove everything else?
    Delete all but digits and dots.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    code-in-time (05-29-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •