Skip to content

Instantly share code, notes, and snippets.

@jarridlima
Created January 23, 2020 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarridlima/965022c848c37919664a47a83c034459 to your computer and use it in GitHub Desktop.
Save jarridlima/965022c848c37919664a47a83c034459 to your computer and use it in GitHub Desktop.
JS REGEX pattern to URL validation
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