How to use the validator.isURL function in validator

To help you get started, we’ve selected a few validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nunux-keeper / keeper-core-api / src / service / download.service.js View on Github external
const down = function (resource) {
      if (!validator.isURL(resource.origin)) {
        logger.error('Unable to download %s. Bad URL.', resource.origin)
        return Promise.resolve('Bad URL: ' + resource.origin)
      }
      logger.debug('Downloading %s to container %s...', resource.origin, container)

      const tryDownload = function () {
        return storage.store(container, resource.key, request(resource.origin), {'Content-Type': resource.type})
      }

      const hostname = url.parse(resource.origin).hostname
      return nodefn.call(dns.resolve4, hostname)
        .then(tryDownload, function (/* e */) {
          logger.error('Unable to download %s. Host cannot be resolved: %s', resource.origin, hostname)
          return Promise.reject(`Host cannot be resolved: ${hostname}`)
        })
    }
github TryGhost / Ghost-Admin / app / validators / user.js View on Github external
website(model) {
        let website = model.get('website');
        // eslint-disable-next-line camelcase
        let isInvalidWebsite = !validator.isURL(website || '', {require_protocol: false})
                          || !validator.isLength(website || '', 0, 2000);

        if (this.isActive(model)) {
            if (!isBlank(website) && isInvalidWebsite) {
                model.get('errors').add('website', 'Website is not a valid url');
                this.invalidate();
            }
        }
    },
github jo0ger / node-server / app / utils / validate.js View on Github external
exports.isUrl = (site = '') => {
    if (!site) return true
    return validator.isURL(site, {
        protocols: ['http', 'https'],
        require_protocol: true
    })
}
github moderntribe / events-gutenberg / src / modules / elements / input / element.js View on Github external
const { type, required } = this.props;

		if ( value.length === 0 ) {
			return ! required;
		}

		let isValid = true;
		switch ( type ) {
			case 'tel':
				isValid = validator.isMobilePhone( value, 'any' );
				break;
			case 'email':
				isValid = validator.isEmail( value );
				break;
			case 'url':
				isValid = validator.isURL( value );
				break;
			case 'number':
				isValid = validator.isNumeric( value );
				break;
		}
		return isValid;
	}
github yargalot / AccessSniff / src / accessSniff.js View on Github external
getContents(file, callback) {

    var contents;
    var isUrl = validator.isURL(file);

    if (isUrl) {
      http.get(file, (response) => {

        response.setEncoding('utf8');

        response.on('data', (data) => {
          callback(data);
        });

      });
    } else {
      fs.readFile(file, 'utf8', (err, data) => {
        callback(data.toString());
      });
    }
github marcocesarato / react-native-input-validator / src / InputValidator.js View on Github external
if (!validator.isHexColor(text)) {
                    is_valid = false;
                }
                break;
            case "identity-card":
                if (!validator.isIdentityCard(text, this.getLocale())) {
                    is_valid = false;
                }
                break;
            case "credit-card":
                if (!validator.isCreditCard(text)) {
                    is_valid = false;
                }
                break;
            case "url":
                if (!validator.isURL(text)) {
                    is_valid = false;
                }
                break;
            case "numeric":
                if (!this.isNumeric(text) && !validator.isNumeric(text)) {
                    is_valid = false;
                }
                break;
            case "integer":
            case "int":
                if (!this.isNumeric(text) && !validator.isNumeric(text)) {
                    is_valid = false;
                }
                break;
            case "real":
            case "float":
github qhacks / qhacks-dashboard / packages / server / webhook / webhook.js View on Github external
function _isValidUrl(url) {
  return url && typeof url === "string" && validator.isURL(url);
}
github jkphl / generator-clearphp / generators / main / index.js View on Github external
validate: function (url) {
                return (url).length ? (validator.isURL(url) || 'The project author\'s website must be a valid URL or empty!') : true;
            }
        }];
github Mewte / InstaSync / web / routes / ajax.js View on Github external
router.post('/me/user_info', function(req,res,next){
	if (!req.user){
		var error = new Error("You must be logged in to access this resource.");
		error.status = 403;
		return next(error);
	}
	var avatar = req.body.avatar;
	var bio = req.body.bio;
	var imgurMatch = /(https?:\/\/)?(www\.)?(i\.)?imgur\.com\/(gallery\/)?([a-zA-Z0-9]+)(\.(jpg|jpeg|png|gif))?/i;
	if (avatar != undefined){
		if (!validator.isURL(avatar,{host_whitelist:["i.imgur.com","www.imgur.com","imgur.com"]})){
			var error = new Error("Only IMGUR URLs are allowed.");
			error.status = 422;
			error.field_name = "avatar";
			error.type = "validation";
			return next(error);
		}
		avatar = avatar.replace(imgurMatch,"$5");
	}
	queries.updateUser(req.user.user_id,avatar,bio).then(function(){
		return queries.getUser(req.user.username);
	}).then(function(user){
		res.json(user);
	}).catch(function(err){
		next(err);
	});
});
github manifoldco / torus-cli / cli / lib / validate.js View on Github external
validate.url = function (input) {
  var error = 'Please enter a valid url';
  return validator.isURL(input) ? true : error;
};