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 9 Subquery In Where Condition
Laravel 9 Subquery In Where Co...

In this article, we will see the laravel 9 subquery in where condition. You can learn how to create subquery in laravel...

Read More

Oct-11-2022

How To Resize Image Before Upload In Laravel 10
How To Resize Image Before Upl...

In this article, we will see how to resize images before uploading in laravel 10. Here, we will learn about laravel 10&n...

Read More

Mar-29-2023

Laravel 10 Apexcharts Bar Chart Example
Laravel 10 Apexcharts Bar Char...

In this article, we will see the laravel 10 apexcharts bar chart example. Here, we will learn about how to create a bar...

Read More

May-24-2023

Carbon Add Hours To Date In Laravel 9
Carbon Add Hours To Date In La...

In this article, we will see carbon add hours to date in laravel 9. Carbon provides addHour and addHours() function...

Read More

Nov-22-2022