URL validation JavaScript header image

How I Validated for Specific URLs in JavaScript

In a pet project that I worked on recently, one of the requirements was to allow users to submit the URL to their Facebook social media profile. This article describes how I ensured that only Facebook profile URLs were submitted. JavaScript was used but it does not matter as much as the algorithm used; and that algorithm is described here. function validateUrl(url, expectedOrigin) { const urlObject = new URL(url); const originPattern = new RegExp(expectedOrigin....

August 18, 2023 · 2 min · Orim Dominic Adah