...

View Full Version : remove invisible char space in string



code-in-time
05-29-2012, 05:29 PM
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?


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

Philip M
05-29-2012, 06:42 PM
<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.

code-in-time
05-29-2012, 06:52 PM
thanks - what does that regex expression mean?


does it mean only allow decimals and dots and remove everything else?

Philip M
05-29-2012, 07:30 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum