javascript
Published on January 26, 2024By DeveloperBreeze
// Function to validate a URL using a regular expression
function isValidURL(url) {
const urlRegex = /^(ftp|http|https):\/\/[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+(\/[^\s]*)?$/;
return urlRegex.test(url);
}
// Example URL to validate
const websiteURL = 'https://www.example.com';
// Check if the URL is valid using the isValidURL function
console.log('Is Valid URL:', isValidURL(websiteURL));
Comments
Please log in to leave a comment.