Created
April 13, 2014 12:21
-
-
Save robozevel/10581699 to your computer and use it in GitHub Desktop.
Extracted from validator.js (https://github.com/chriso/validator.js)
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
var isValidUrl = (function() { | |
var protocols = ["http", "https", "ftp"]; | |
var requireProtocol = false; | |
var requireTLD = true; | |
var pattern = new RegExp('^(?!mailto:)(?:(?:' + protocols.join('|') + ')://)' + (requireProtocol ? '' : '?') + '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-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,}))' + (requireTLD ? '' : '?') + ')|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i'); | |
return function(str) { | |
return (typeof str === "string") && str.length < 2083 && pattern.test(str); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment