Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Remove Spaces from String with Regular Expression

Oct 9, 2012
Introduction

Here I will explain how to remove or delete spaces from string using
JQuery in asp.net.

Description:
  
In previous articles I explained jQuery Remove first/last character from string, Best Drag and Drop Plugin examples, Scroll back to top plugin Examples,
Password strength jquery plugin examples and many articles relating to JQuery. Now I will explain how to remove or delete spaces from string using JQuery in asp.net.

To remove or delete spaces from string we need to use regular expression for that we need to write codesnippet like as shown below

Remove all the spaces from string


<script type="text/javascript">
$(document).ready(function() {
var str = ' Welcome To Aspdotnet  -  Suresh '
var newstr = str.replace(/\s/g,'') // Remove spaces from string
alert(newstr);
})
</script>
If you want check this code in sample check below code

Example:


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>jQuery Remove or Delete spaces from string in asp.net</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
String : <b>Welcome To Aspdotnet  -  Suresh</b>
<input type="button" id="btnRemove" value="Remove Spaces From String" /><br /><br />
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#btnRemove').click(function() {
var str = ' Welcome To Aspdotnet  -  Suresh '
var newstr = str.replace(/\s/g, '') // Remove spaces from string
alert(newstr);
});
});
</script>
</form>
</body>
</html>
Live Demo

To check Live demo click on below button

String : Welcome To Aspdotnet - Suresh


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Anand Patel said...







Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.