javascript determine if string is valid url
function isValidURL(string) {
var res = string.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
return (res !== null)
};
var testCase1 = "http://en.wikipedia.org/wiki/Procter_&_Gamble";
alert(isValidURL(testCase1));
function isValidHttpUrl(string) {
let url;
try {
url = new URL(string);
} catch (_) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
}
Also in JavaScript:
- how to disable menu bar in browser using javascript
- petition the lord with prayer
- array sorting javascript mergesort
- angular bootstrap
- Trouble setting up sample table. “Could not find matching row model for rowModelType clientSide”
- jquery disable class attribute
- add webpack to react project tutorial
- check how many of a word is in a string
- javascript return value from async function site:stackoverflow.com
- slice in javascript
- Expected an assignment or function call and instead saw an expression
- Robux gift
- how to compare javascript objects
- how to remove 000webhost watermark 2019
- array con javascript
- get top items from json object
- merge two strings with alternate characters javascript
- js check if string is number
- /on in jquery
- class merging
- convert date format from yyyy-mm-dd to dd-mm-yyyy using value javascript
- javascript console input
- sum in javascript
- JavaScript's automatic semicolon insertion (ASI)