-
-
Save jarridlima/965022c848c37919664a47a83c034459 to your computer and use it in GitHub Desktop.
JS REGEX pattern to URL validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let patternUrl = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/ | |
// source: https://www.regextester.com/94502 | |
// =============================== | |
// Test strings: | |
// =============================== | |
// https://www.example.com | |
// http://www.example.com | |
// www.example.com | |
// example.com | |
// http://blog.example.com | |
// http://www.example.com/product | |
// http://www.example.com/products?id=1&page=2 | |
// http://www.example.com#up | |
// http://255.255.255.255 | |
// 255.255.255.255 | |
// http://www.site.com:8008 | |
// INVALID => http://invalid.com/perl.cgi?key= | http://web-site.com/cgi-bin/perl.cgi?key1=value1&key2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment