I think the question title seems to explain eveything. I want to detect whether a string is in URL format or not using javascript.
Any help appreciated.
I think the question title seems to explain eveything. I want to detect whether a string is in URL format or not using javascript.
Any help appreciated.
Had the same task, but all of regex that I found online to check validity of a URL were failed in some test cases.
Here is the regex that worked everything:
/^(http:\/\/www\.|https:\/\/www\.|www\.)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?/
However, If the URL was like: google.com It accepted it as valid (which in my specific case, was considered as invalid)
It worked the best I had found. Worked like a charm!
When given the option, I prefer the simplest solution.
Use _.startsWith(string, 'http') if: