File indexing completed on 2025-02-16 04:34:23
0001 // 0002 // Regular Expression for URL validation 0003 // 0004 // Author: Diego Perini 0005 // Created: 2010/12/05 0006 // Updated: 2018/09/12 0007 // Modified: 2019/01/05 (Simon Schmeisser) 0008 // License: MIT 0009 // 0010 // SPDX-FileCopyrightText: 2010-2018 Diego Perini (http://www.iport.it) 0011 // 0012 // SPDX-License-Identifier: MIT 0013 // 0014 // the regular expression composed & commented 0015 // could be easily tweaked for RFC compliance, 0016 // it was expressly modified to fit & satisfy 0017 // these test for an URL shortener: 0018 // 0019 // http://mathiasbynens.be/demo/url-regex 0020 // 0021 // Notes on possible differences from a standard/generic validation: 0022 // 0023 // - utf-8 char class take in consideration the full Unicode range 0024 // - TLDs have been made mandatory so single names like "localhost" fails 0025 // - protocols have been restricted to ftp, http and https only as requested 0026 // 0027 // Changes: 0028 // 0029 // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255 0030 // first and last IP address of each class is considered invalid 0031 // (since they are broadcast/network addresses) 0032 // 0033 // - Made starting path slash optional (http://example.com?foo=bar) 0034 // - Allow a dot (.) at the end of hostnames (http://example.com.) 0035 // - Allow an underscore (_) character in host/domain names 0036 // - Check dot delimited parts length and total length 0037 // - Made protocol optional, allowed short syntax // 0038 // 0039 // local changes: 0040 // 0041 // - removed "short syntax //", either http://, https://, ftp:// or just the domain 0042 // 0043 // Compressed one-line versions: 0044 // 0045 // Javascript regex version 0046 // 0047 // /^(?:(?:https?|ftp):\/\/)?(?:\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-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i 0048 // 0049 // PHP version (uses % symbol as delimiter) 0050 // 0051 // %^(?:(?:https?|ftp):\/\/)?(?:\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-z0-9\x{00a1}-\x{ffff}][a-z0-9\x{00a1}-\x{ffff}_-]{0,62})?[a-z0-9\x{00a1}-\x{ffff}]\.)+(?:[a-z\x{00a1}-\x{ffff}]{2,})\.?))(?::\d{2,5})?(?:[/?#]\S*)?$%iuS 0052 // 0053 var re_weburl = new RegExp( 0054 "^" + 0055 // protocol identifier (optional) 0056 "(?:(?:https?|ftp):\\/\\/)?" + 0057 // user:pass BasicAuth (optional) 0058 "(?:\\S+(?::\\S*)?@)?" + 0059 "(?:" + 0060 // IP address dotted notation octets 0061 // excludes loopback network 0.0.0.0 0062 // excludes reserved space >= 224.0.0.0 0063 // excludes network & broacast addresses 0064 // (first & last IP address of each class) 0065 "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + 0066 "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + 0067 "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + 0068 "|" + 0069 // host & domain names, may end with dot 0070 // can be replaced by a shortest alternative 0071 // (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+ 0072 "(?:" + 0073 "(?:" + 0074 "[a-z0-9\\u00a1-\\uffff]" + 0075 "[a-z0-9\\u00a1-\\uffff_-]{0,62}" + 0076 ")?" + 0077 "[a-z0-9\\u00a1-\\uffff]\\." + 0078 ")+" + 0079 // TLD identifier name, may end with dot 0080 "(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" + 0081 ")" + 0082 // port number (optional) 0083 "(?::\\d{2,5})?" + 0084 // resource path (optional) 0085 "(?:[/?#]\\S*)?" + 0086 "$", "i" 0087 );