1loc icon indicating copy to clipboard operation
1loc copied to clipboard

Validate a URL

Open rajlomror opened this issue 4 years ago • 2 comments

One liner JavaScript function to check whether a given value is a valid URL or not.

rajlomror avatar Oct 02 '20 08:10 rajlomror

Hey, @rajlomror, thanks for your contribution! However, I have some doubts about this RegExp. Did you write it yourself or copied from somewhere? Why are there some IPs separate? It seems that the use of this is for something else (like figuring if the URL might be on the local network).

In general, it's very thicky to write regexps for such general concepts. Similar to an email, the result is either super complex and opinionated or trivial. Maybe it would be better to figure out how to take advantage of build-in URL 😉

robinpokorny avatar Dec 13 '21 20:12 robinpokorny

This solution make use of the URL native API : const isUrl = string => { try { return Boolean(new URL(string)); } catch(e){ return false; } }

elkarouani avatar Dec 13 '21 20:12 elkarouani