Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In JavaScript coding I am getting the value like 2365 2365.
I would like to remove the space between numbers, it should be 23652365.

How should I do this?
Kindly help.

Thanks
Harshal Raut
Posted
Updated 25-Jan-14 2:37am
v3

Try this:
JavaScript
var withSpaces = prompt('Enter a number please:');
var withoutSpaces = withSpaces.replace(/\s/g, '');

The g after /\s/ means global match, that means that it will remove all whitespace. If you remove the g then it will only remove the first space/tab/newline.

Online demo: http://jsfiddle.net/ProgramFOX/RwF9Y/[^]
 
Share this answer
 
v2
Comments
R Harshal 25-Jan-14 8:56am    
Thanks Buddy..Great
Thomas Daniels 25-Jan-14 9:05am    
You're welcome!
Hello ,

It is better to share your code but in a generic way this is the solution for your query

JavaScript
val = val.replace(/\s/g, '')


Where g stands for general


All the best:)Pls write back if you need any support.
 
Share this answer
 
Comments
R Harshal 25-Jan-14 8:42am    
Thanks for your reply.

This is my code...

customerLoanRecord.MobileNo1 = $('#txtMobile1').val();
In $('#txtMobile1').val();i am getting the mobile number but it is like this 9875 569873 which i dont want.
I need number like 9875569873.
R Harshal 25-Jan-14 8:45am    
its not working kindly help brother.
Thanks
R Harshal 25-Jan-14 8:55am    
Thanks Brother its working..
karthik Udhayakumar 25-Jan-14 8:57am    
Welcome Bro :)
Try
JavaScript
var str = "2365 2365"
str = str.replace(/\s+/g, '');
 
Share this answer
 
Comments
R Harshal 25-Jan-14 8:55am    
Thanks Buddy its working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900