DEV Community


Posted on • Originally published at

How To Remove Spaces Using JQuery

In this post i will explain you how to remove space using jquery, some times we have requirments to remove white space from textbox or many time users added unnecessary space in field which occupied more space in databese so here we will remove white spaces from string using jquery or javascript.

Here i will show you example to remove white space from textbox, in this example i have added one text box to add string and one submit button and you will get output in alertbox and jquery remove all whitespaces from string.

<html lang="en">
    <title>How to Remove Spaces using jQuery -</title>  
    <script src=""></script>

  <h1>How to Remove Spaces using jQuery -</h1>
  <textarea class="content-text">
    This is example   how to remove space using jquery.
  <button>Remove Space</button>

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

Enter fullscreen mode Exit fullscreen mode

You might also like :

Read Also : How To Check Email Already Exist Or Not In Laravel

Read Also : Laravel 8 Google Recaptcha Example

Discussion (0)