53 words, 1 min read

The URL object in JavaScript provides a built-in way to parse and validate URLs. It is robust, handles complex cases, and doesn’t require writing or maintaining custom regular expressions neither does it require an external library.

function isValid(url) {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}