How can I remove the url from a string? I url might not start with https or http. How can I do this using javascript? I want to prevent people from sending bad urls to my users through the sign up form.
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
You can use a regular expression that matches the URLs and replace them with an empty string using the .replace() method.
You should definitely use regular expressions.
You can find the answer of how to create a regular expression for URLs here: What is a good regular expression to match a URL?
Once you have this regular expression, you can do something like this: (And make sure the regular expression has the g modifier flag to cath all instances)