JQuery-Remove all spaces from string using javascript/JQuery/Regular expressions.
Posted by Raj
Remove all spaces from string using javascript/JQuery/Regular expressions.
In this tutorial, I will explain how to remove all spaces in a string using jquery,
remove all occurences of a character from a string.
I need to remove spaces in the string.I will use JQuery/Regular expressions/javascript to replace spaces from string.
You can replace string with '_','-'....etc.
Removing extra space from the string using javascript and Regular expression is very easy.
<script type="text/javascript">
function removeSpaces(str)
{
var s=str.replace(/\s/g, "");
return s;
}
var new_str=removeSpaces('jquery remove space from string using javascript');
</script>
Removing extra space from the string using JQuery and Regular expression.
<html>
<head>
<title>Remove spaces in a string using jquery</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script></script>
<script type="text/javascript">
$(function ()
{
var str = $("#str").html();
alert(str.replace(/\s/g, ""));
});
</script>
</head>
<body>
<p><span id="str">Remove spaces in a string using jquery</span></p>
</body>
</html>
Removing extra space from the string using Javascript split and join function.
<script type="text/javascript">
function removeSpaces(str) {
return str.split(' ').join('');
}
var s=removeSpaces('jquery remove space from string using javascript');
</script>
I hope this tutorial will help you to remove spaces from string using JQuery/javascript/Regular expressions.
In this tutorial, I will explain how to remove all spaces in a string using jquery,
remove all occurences of a character from a string.
I need to remove spaces in the string.I will use JQuery/Regular expressions/javascript to replace spaces from string.
You can replace string with '_','-'....etc.
Removing extra space from the string using javascript and Regular expression is very easy.
<script type="text/javascript">
function removeSpaces(str)
{
var s=str.replace(/\s/g, "");
return s;
}
var new_str=removeSpaces('jquery remove space from string using javascript');
</script>
Removing extra space from the string using JQuery and Regular expression.
<html>
<head>
<title>Remove spaces in a string using jquery</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script></script>
<script type="text/javascript">
$(function ()
{
var str = $("#str").html();
alert(str.replace(/\s/g, ""));
});
</script>
</head>
<body>
<p><span id="str">Remove spaces in a string using jquery</span></p>
</body>
</html>
Removing extra space from the string using Javascript split and join function.
<script type="text/javascript">
function removeSpaces(str) {
return str.split(' ').join('');
}
var s=removeSpaces('jquery remove space from string using javascript');
</script>
I hope this tutorial will help you to remove spaces from string using JQuery/javascript/Regular expressions.
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
JAVASCRIPT,
JQuery,
jquery remove spaces,
jquery trim,
jquery trim spaces,
jquery trim string,
js trim whitespace,
leading and trailing spaces,
trim jquery,
trim spaces
.You can leave a response, or trackback from your own site.