Well, it seems likely that your problem is not one of "how do I insert spaces into a string" but rather one of "how can I display several space characters in a row in a web-page"
You may well wish to escape the text entered by the user.
So, if the user enters
Naveen Kumar
, you will have a string that contains the text
"Naveen Kumar"
However, when you display it, the browser will turn those 5 spaces "_____" into a single one.
If you use the javascript string replace function, it will only replace the first occurance of a string.
Code:
var str = "Naveen_____Kumar";
str.replace("_", ".");
Result:
str = "Naveen.____Kumar";
Code:
var str = "Naveen_____Kumar";
var regex = new RegExp('_', 'g');
str = str.replace(regex, ".");
Result:
str = "Naveen.....Kumar";
Lastly, the code for an escaped space (' ') character is ' ' - you can replace the text "." with " "