1function isValidURL(string) {
2 var res = string.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
3 return (res !== null)
4};
5
6var testCase1 = "http://en.wikipedia.org/wiki/Procter_&_Gamble";
7
8alert(isValidURL(testCase1));
9
1<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
2<script type="text/javascript">
3 $(document).ready(function() {
4 if (window.location.href.indexOf("franky") > -1) {
5 alert("your url contains the name franky");
6 }
7 });
8</script>
1const isAbsoluteUrl = url => /^[a-z][a-z0-9+.-]*:/.test(url);
2
3// Example
4isAbsoluteUrl('https://1loc.dev'); // true
5isAbsoluteUrl('https://1loc.dev/foo/bar'); // true
6isAbsoluteUrl('1loc.dev'); // false
7isAbsoluteUrl('//1loc.dev');