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

167
Views
Replace Empty URL Space with %20 for HTML Link

I have a function that I thought I had working to replace a URL with an HTML link when someone submits something on a form of ours. If the users enters a URL with a space, for example:

company.sharepoint.com/sites/testsite/shared documents/forms/allitems.aspx

The function cuts off anything after the space.

Below is my code:

ReplaceURLwithHTMLLinks: function(text) {
 if (text !=null && text.length > 0) {
  var exp = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|}{\[\]\(\)"'])/i;

  if (text.indexOf("-") > -1) {
   
   var linkText;

   if (text.indexOf("company.sharepoint.com") > -1
    linkText = text.substring(0, text.indexOf('-') - 1) + " - SharePoint";
   else
    linkText = text.substring(0, text.indexOf('-') - 1);

   var newLink = text.replace(exp, "<a target='_blank' rel='noopener noreferrer' href='$1'>" + linkText + "</a>";

   return newLink.substring(newLink.indexOf("<a"));
   }
 }

 else {
  return test;
  }
}

I am trying to find out how to replace any blank spaces with a %20 to still allow the HTML Link to load properly

Thanks

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You could try this?

text.replace(/\s/g, "%20");

it replaces all the empty spaces with %20

about 4 years ago · Santiago Gelvez Report
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!