How To Remove Spaces Using JQuery

Websolutionstuff | Aug-10-2020 | Categories : Laravel PHP jQuery

In this article, we will explain to you how to remove extra space using jquery. many times we have requirements to remove white space from the textbox or many times users added unnecessary space in fields which occupied more space in the database.

I am giving you a very simple example to remove white space from the textbox. in this example, I have added one text box to add a string and one submit button and you will get output in an alert box.

So, let's see remove blank space from string jquery or javascript remove all whitespaces from a string.

<html lang="en">
<head>
    <title>How to remove spaces using JQuery - websolutionstuff.com</title>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>

<div>
  <h1>How to remove spaces using JQuery - websolutionstuff.com</h1>
  <textarea class="content-text">
  	This is demo how to remove space using jquery.
  </textarea>
  <button>Remove Space</button>
</div>


<script type="text/javascript">
  $("button").click(function(){
  	  removeText = $(".content-text").val();
      var rm_space = removeText.replace(/ /g,'');
      alert(rm_space);
  });
</script>


</body>
</html>

 


You might also like:

Recommended Post
Featured Post
Laravel 11: when Blade Directive Example
Laravel 11: when Blade Directi...

In this tutorial, I’ll show you how to use the @when directive in Laravel 11 to conditionally render content in yo...

Read More

Oct-28-2024

How To Connect ftp Server Using php
How To Connect ftp Server Usin...

Hello All, In this post i will show you how to connect ftp server using php. PHP provide inbuilt functio...

Read More

May-12-2021

Real-Time Data Analysis in Laravel with Python
Real-Time Data Analysis in Lar...

In this guide, I’ll show you how to connect Python's powerful data analysis capabilities, specifically using P...

Read More

Nov-19-2024

Character Count In Textarea
Character Count In Textarea

In this article, we will explain to you how to count characters from textarea. many times a client has requirements...

Read More

Jul-08-2020