Created
September 12, 2017 14:03
-
-
Save mikejavier/a891deda48ed43fc5a4110f606cc46b3 to your computer and use it in GitHub Desktop.
Regular Expression for Perfect URL validation
This file contains hidden or 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
| // | |
| // Regular Expression for Perfect URL validation | |
| // License: MIT | |
| // | |
| /^(?:(?:https?):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/ | |
| // | |
| // DEMO | |
| // | |
| http://regexr.com/3gntg |
This file contains hidden or 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
| ftp://www.example.com | |
| file://www.example.com | |
| https://www.example.com | |
| http://www.example.com | |
| www.example | |
| www.example.com | |
| example.com | |
| .example.com | |
| http://localhost | |
| http://127.0.0.1/dashboard/ | |
| https://www.instagram.com/p/BY79VWMj5E4/?hl=pt-br&taken-by=postgrain | |
| http://app.postgrain.local/dashboard/ | |
| http://t.co | |
| http://google.com/image?id=aijshakjbs | |
| http://74.125.21.138/image?id=aijshakjbs | |
| 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://invalid.com/perl.cgi?key= | |
| http://web-site.com/cgi-bin/perl.cgi?key1=value1&key2 | |
| http://invalid.com/perl.cgi?key=158&url=http%3A%2F%2Fa.com%2F%3Fq%3Dquery%26n%3D10 | |
| http://invalid.com/perl.cgi?key= | |
| http://www.site.com:8008 | |
| http://dominio.com.br/index.html?q=http:dominio.com.br | |
| [email protected] | |
| http://twitter.com/oauth/request_token/intent/user_original_referer=https%3A%2F%2Ftwitter.com%2Fsettings%2Fwidgets%2Fnew |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment