DEV Community


How To Remove Spaces Using JQuery

websolutionstuff profile image Websolutionstuff Originally published at ・1 min read

In this tutorial I will explain you how to remove extra space using jquery, many times we have requirments to remove white space from textbox, or many time users added unnecessary space in field which occupied more space in database.

I am giving you very simple 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.

<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 demo 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

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

Discussion (0)

Editor guide