Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Remove all spaces in url exclude in text content in jquery sanitizer

I have a jquery html sanitizer function it removes (almost) all unwanted codes in content and in url, but spaces in url.

It doesn't remove spaces in url

When I add replace(/\s+/gi, ''); to the function then it removes spaces in content is well and I get bunch of text without spaces.

What I want to do is, remove all spaces just in url not in content.

Here is my the code :

(function($) {
   $.sanitize = function(input) {
   var output = input.replace(/<script[^>]*?>.*?<\/script>/gi, '').
   replace(/<[\/\!]*?[^<>]*?>/gi, '').
   replace(/<style[^>]*?>.*?<\/style>/gi, '').
   replace(/<![\s\S]*?--[ \t\n\r]*>/gi, '').
   replace(/&nbsp;/g, '');
  return output;
    };
})(jQuery);

$(function() {
    $('#sanitize').click(function() {
        var $input = $('#input').val();
        $('#output').text($.sanitize($input));
    });

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea cols="30" rows="10" id="input"></textarea>
<p><button id="sanitize">Sanitize</button></p>
<p id="output"></p>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!