Skip to content

Commit 0871055

Browse files
authored
Create validURL.js
1 parent be28606 commit 0871055

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Regex/validURL.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const validURL = (str) => {
2+
const pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
3+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
4+
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
5+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
6+
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
7+
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
8+
return !!pattern.test(str);
9+
}
10+
11+
console.log(validURL("https://www.google.com/"));

0 commit comments

Comments
 (0)