xxxxxxxxxx
const re = /^((ftp|http|https):\/\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_-]+(\.[a-zA-Z]+)+((\/)[\w#]+)*(\/\w+\?[a-zA-Z0-9_]+=\w+(&[a-zA-Z0-9_]+=\w+)*)?$/gm
Yup.string().matches(re,'URL is not valid')
xxxxxxxxxx
const yup = require('yup');
// Define the validation schema for URL
const urlSchema = yup.string().url().required();
// Test the validation with a URL
const testUrl = 'https://example.com';
urlSchema.validate(testUrl)
.then(validUrl => {
console.log('Valid URL:', validUrl);
})
.catch(error => {
console.log('Invalid URL:', error.message);
});