Validates that a fields value is a valid URL.
480792
def is_url():
    
    # Stolen from Django
    regex = re.compile(
        r'^(?:http|ftp)s?://' # http:// or https://
        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
        r'localhost|' #localhost...
        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
        r'(?::\d+)?' # optional port
        r'(?:/?|[/?]\S+)$', re.IGNORECASE)

    def validate(value):
        if not regex.match(value):
            return e("{} is not a valid URL", value)
    return validate
1110856
function _validateBaseUrl(url) {
        var result = "";
        // Empty url means "no server mapping; use file directly"
        if (url === "") {
            return result;
        }

        var obj = PathUtils.parseUrl(url);
        if (!obj) {
            result = Strings.BASEURL_ERROR_UNKNOWN_ERROR;
        } else if (obj.href.search(/^(http|https):\/\//i) !== 0) {
            result = StringUtils.format(Strings.BASEURL_ERROR_INVALID_PROTOCOL, obj.href.substring(0, obj.href.indexOf("//")));
        } else if (obj.search !== "") {
            result = StringUtils.format(Strings.BASEURL_ERROR_SEARCH_DISALLOWED, obj.search);
        } else if (obj.hash !== "") {
            result = StringUtils.format(Strings.BASEURL_ERROR_HASH_DISALLOWED, obj.hash);
        } else {
            var index = url.search(/[ \^\[\]\{\}<>\\"\?]+/);
            if (index !== -1) {
                result = StringUtils.format(Strings.BASEURL_ERROR_INVALID_CHAR, url[index]);
            }
        }

        return result;
    }
112360
def validate(self, value):
        """"""
        if value is not None and not isinstance(value, bool):
            raise ValidationError("field must be a boolean")

        super().validate(value)
1148556
def validate_url(url, allowed_response_codes=None):
    
    allowed_response_codes = [200] if allowed_response_codes is None else allowed_response_codes

    # link calls a js function, do not try to open
    if str(url).startswith('javascript:'):
        return True

    try:
        response = urllib2.urlopen(urllib2.Request(url))
    except urllib2.URLError:
        raise AssertionError('Url was invalid and could not be opened: {url}'.format(url=url))

    if response.code not in allowed_response_codes:
        raise AssertionError('Invalid response code {response_code} from url: {url}'
                             .format(response_code=response.code, url=url))
    return True
1101114
protected function _validate_url($value)
    {
        $value = trim($value);

        if ($value === '') {
            return '';
        }

        if (filter_var($value, FILTER_VALIDATE_URL) !== false) {
            $parts = explode('://', $value, 2);
            $scheme = strtolower($parts[0]);
            $path = $parts[1];
            if ($scheme !== 'http' && $scheme !== 'https') {
                return null;
            } else {
                return $scheme . '://' . $path;
            }
        } else {
            return null;
        }
    }
875418
def validate(self, value):
        """"""
        try:
            self._choice = IPAddress(value)
        except (ValueError, AddrFormatError):
            self.error_message = '%s is not a valid IP address.' % value
            return False
        if self._choice.is_netmask():
            return True
        else:
            self.error_message = '%s is not a valid IP netmask.' % value
            return False
801440
def validate(url, schemes=None, tlds=None, private=None, local=None,
             credentials=None):
    '''
    
    '''
    url = url.strip()

    private = config_for(private, 'URLS_ALLOW_PRIVATE')
    local = config_for(local, 'URLS_ALLOW_LOCAL')
    credentials = config_for(credentials, 'URLS_ALLOW_CREDENTIALS')
    schemes = config_for(schemes, 'URLS_ALLOWED_SCHEMES')
    tlds = config_for(tlds, 'URLS_ALLOWED_TLDS')

    match = URL_REGEX.match(url)
    if not match:
        error(url)

    scheme = (match.group('scheme') or '').lower()
    if scheme and scheme not in schemes:
        error(url, 'Invalid scheme {0}'.format(scheme))

    if not credentials and match.group('credentials'):
        error(url, 'Credentials in URL are not allowed')

    tld = match.group('tld')
    if tld and tld not in tlds and tld.encode('idna') not in tlds:
        error(url, 'Invalid TLD {0}'.format(tld))

    ip = match.group('ipv6') or match.group('ipv4')
    if ip:
        try:
            ip = IPAddress(ip)
        except AddrFormatError:
            error(url)
        if ip.is_multicast():
            error(url, '{0} is a multicast IP'.format(ip))
        elif not ip.is_loopback() and ip.is_hostmask() or ip.is_netmask():
            error(url, '{0} is a mask IP'.format(ip))

    if not local:
        if ip and ip.is_loopback() or match.group('localhost'):
            error(url, 'is a local URL')

    if not private and ip and ip.is_private():
        error(url, 'is a private URL')

    return url
897571
function validateField ( fldID, fieldMeta, value ) {
        var res  = {}
          , errs = checkByAll( fieldMeta.validators, value, fieldMeta );
        res[ fldID ] = errs.length ? errs : null;
        return res;
    }
1322983
private function _validateUrl ($value)
    {
        $pattern = '/^{schemes}:\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(?::\d{1,5})?(?:$|[?\/#])/i';
        $validSchemes = ['http', 'https'];
        $pattern = str_replace('{schemes}', '(' . implode('|', $validSchemes) . ')', $pattern);
        if (!preg_match($pattern, $value)) {
            return false;
        }
        return true;
    }
442590
def validate_url(url):
    

    scheme = url.split('://')[0].lower()
    if scheme not in url_schemes:
        return False
    if not bool(url_regex.search(url)):
        return False
    return True
340270
def validate(self, value):
        ''''''
        if self.blank and value == '':
            return True
        if URIValidator.uri_regex.match(value):
            self._choice = value
            return True
        else:
            self.error_message = '%s is not a valid URI' % value
            return False
157805
protected function validateUrlDownload()
    {
        $invalid = array();

        foreach ($this->getSubmitted('sources') as $line => $url) {
            $line++;
            if (filter_var($url, FILTER_VALIDATE_URL) === false) {
                $invalid[] = $line;
            }
        }

        if (!empty($invalid)) {
            $this->setError('sources', $this->text('Error on line @num', array('@num' => implode(',', $invalid))));
        }
    }
200458
public function validateUrl($url)
    {
        if (empty($url)) {
            throw new \InvalidArgumentException('The field cannot be empty.');
        }

        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            throw new \InvalidArgumentException('The field requires a valid URL.');
        }

        return $url;
    }
1286448
def validate_url(uri_string):
    """"""
    try:
        result = urlparse(uri_string)
        has_elements = all([result.scheme, result.netloc, result.path])
        is_http = result.scheme == "http" or result.scheme == "https"
        return True if has_elements and is_http else False

    except Exception:
        return False
1100731
public static boolean isValidUrl(String url) {
        try {
            if (Strings.isNullOrEmpty(url)) {
                return false;
            }
            new URL(url);
            return true;
        } catch (MalformedURLException e) {
            return false;
        }
    }
523427
function validateUrl (url) {
  if (!url) {
    return option.some('Url is not specified')
  }
  if (typeof url !== 'string') {
    return option.some('Url should be type of string')
  }
  return option.none
}
685676
def is_url(value):
    ""
    if not isinstance(value, str):
        return False
    if not value.startswith('http://') and not value.startswith('https://'):
        return False
    # Any whitespace at all is invalid
    if whitespace_re.search(value):
        return False
    return True