url validator javascript
function validURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','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}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
return (res !== null)
};
var testCase1 = "http://en.wikipedia.org/wiki/Procter_&_Gamble";
alert(isValidURL(testCase1));
Also in JavaScript:
- find element by object field vuejs
- remove a specific element from an array
- function range() as range js
- onclick open modal jquery
- 231105 color
- function redirect javascript
- get only unique values from array javascript
- javascript regex only letters and spaces
- cm to inches
- react native post api method
- computed vue js
- mongodb js insertmany
- setimmediate not working
- sum all elements in array javascript
- docker how to restart container at coputer startup
- react js material ui
- run length encoding javascript
- input onchange react type file
- jquery if checkbox is checked
- angular ng-click toggle class
- discord.js wait seconds
- change the value in checkbox by button react
- check if even or odd javascript
- js go to see history