modified regex

- it matched "www.google" which shouldnt be possible
This commit is contained in:
rawalcher 2025-01-27 12:05:35 +01:00
parent 611f9ecc5f
commit b717bd96b1

View file

@ -2,7 +2,8 @@ document.getElementById("urlInput").addEventListener("input", function() {
const urlInput = document.getElementById("urlInput"); const urlInput = document.getElementById("urlInput");
const shortenButton = document.getElementById("shortenButton"); const shortenButton = document.getElementById("shortenButton");
const urlPattern = /^(https?:\/\/)?([\w\d-]+\.)+[a-z]{2,6}(\/[\w\d-]*)*\/?$/i; const urlPattern = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/i
const isValid = urlPattern.test(urlInput.value); const isValid = urlPattern.test(urlInput.value);
if (isValid) { if (isValid) {