function validURL(str) {
var pattern = new RegExp('^(https?://)?'+ // protocol
'((([a-zd]([a-zd-]*[a-zd])*).)+[a-z]{2,}|'+ // domain name
'((d{1,3}.){3}d{1,3}))'+ // OR ip (v4) address
'(:d+)?(/[-a-zd%_.~+]*)*'+ // port and path
'(?[;&a-zd%_.~+=-]*)?'+ // query string
'(#[-a-zd_]*)?$','i'); // fragment locator
return !!pattern.test(str);
}
function isValidURL(string) {
var res = string.match(/(http(s)?://.)?(www.)?[-a-zA-Z0-9@:%._+~#=]{2,256}.[a-z]{2,6}([-a-zA-Z0-9@:%_+.~#?&//=]*)/g);
return (res !== null)
};
function isValidHttpUrl(string) {
let url;
try {
url = new URL(string);
} catch (_) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
}
function isValidHttpUrl(string) {
let url;
try {
url = new URL(string);
} catch (_) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
}
validateurl
validate url