How to use the validator.isLength 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 schahriar / Galleon / seascape / routes / users.js View on Github external
password: req.param('password')
	}

	// REGEX to match:
	// * Between 4 to 64 characters
	// * Special characters allowed (_)
	// * Alphanumeric
	// * Must start with a letter
	if(!validator.isEmail(user.email))
		return res.status(500).json({ error: "Invalid Email", code: "!U" });

	// REGEX to match:
	// * Between 2 to 256 characters
	// * Special characters allowed (&)
	// * Alpha
	if((!validator.matches(user.name, /^([ \u00c0-\u01ffa-zA-Z-\&'\-])+$/))&&(validator.isLength(user.name,2,256)))
	   return res.status(500).json({ error: "Invalid Name", code: "!N" });

	// REGEX to match:
	// * Between 6 to 20 characters
	// * Special characters allowed (@,$,!,%,*,?,&)
	// * Alphanumeric
	if(!validator.matches(user.password, /^(?=.*[a-zA-Z])[A-Za-z\d$@$!%*?&]{6,20}/))
		return res.status(500).json({ error: "Invalid Password", code: "!P" });

	bcrypt.hash(user.password, 10, function(error, hash) {
		if(error) return res.status(500).json({ error: error });
		
		console.log(hash);
		req.database.models.users.create({
			email: user.email,
			name: user.name,
github panitw / easy-rpm / tasks / lib / spec-validator.js View on Github external
emptyPath: false,
            newlinePath: false,
            nonIntegerMode: false,
            numericUser: false,
            numericGroup: false
        },
        warnings = {
            nonStandardMode: false
        },
        i, file;

    for (i = 0; i < files.length; i++) {
        file = files[i];

        // Check path.
        if (!validator.isLength(file.path, 1)) {
            errors.emptyPath = true;
        } else if (validator.contains(file.path, '\n')) {
            errors.newlinePath = true;
        }

        // Check mode.
        if (validator.isLength(file.mode, 1)) {
            validateMode(file.mode, errors, warnings);
        }

        if (validator.isLength(file.user, 1) && validator.isInt(file.user)) {
            errors.numericUser = true;
        }

        if (validator.isLength(file.group, 1) && validator.isInt(file.group)) {
            errors.numericGroup = true;
github ThisIsRudigo / firebaseauth / user / account.js View on Github external
if (photoUrl && typeof(photoUrl) === 'function'){
		callback = photoUrl
		photoUrl = null;
	}

	if (typeof(callback) !== 'function'){
		throw new Error('No valid callback function defined');
		return;
	}

	if (typeof(token) !== 'string' || token.trim().length === 0){
		callback(utils.invalidArgumentError('Token'));
		return;
	}

	if (!name || !validator.isLength(name, {min: 2})){
		callback(utils.invalidArgumentError('Name'));
		return;
	}

	if (photoUrl && !validator.isURL(photoUrl)) {
		callback(utils.invalidArgumentError('Photo Url. Not a valid URL'));
		return;
	}

	var payload = {
		idToken: token,
		displayName: name,
		returnSecureToken: true
	}

	if (photoUrl)
github ZZROTDesign / alpine-ghost / ghost / core / server / models / user.js View on Github external
function validatePasswordLength(password) {
    return validator.isLength(password, 8);
}
github TryGhost / Ghost-Admin / app / validators / post.js View on Github external
emailSubject(model) {
        if (!validator.isLength(model.emailSubject || '', 0, 300)) {
            model.errors.add('emailSubject', 'Email Subject cannot be longer than 300 characters.');
            this.invalidate();
        }
    },
github rtCamp / wp-decoupled / validator / checkout.js View on Github external
const addErrorAndSanitizedData = ( fieldName, errorContent, min, max, type = '', required ) => {

		const postCodeLocale = config.postCodeLocale ? config.postCodeLocale : '';
		/**
		 * Please note that this isEmpty() belongs to validator and not our custom function defined above.
		 *
		 * Check for error and if there is no error then sanitize data.
		 */
		if ( ! validator.isLength( data[ fieldName ], { min, max } ) ){
			errors[ fieldName ] = `${errorContent} must be ${min} to ${max} characters`;
		}

		if ( 'email' === type && ! validator.isEmail( data[ fieldName ] ) ){
			errors[ fieldName ] = `${errorContent} is not valid`;
		}

		if ( 'phone' === type && ! validator.isMobilePhone( data[ fieldName ] ) ) {
			errors[ fieldName ] = `${errorContent} is not valid`;
		}

		if ( 'postCode' === type && postCodeLocale && ! validator.isPostalCode( data[ fieldName ], postCodeLocale ) ) {
			errors[ fieldName ] = `${errorContent} is not valid`;
		}

		if ( required && validator.isEmpty( data[ fieldName ] ) ) {
github RikeyChen / fups / validation / fups.js View on Github external
module.exports = function validateFupInput(data) {
  let errors = {};

  data.text = validText(data.text) ? data.text : '';

  if (!Validator.isLength(data.text, {min: 25, max: 280 })) {
    errors.text = 'Fup must be between 25 and 280 characters';
  }

  if (Validator.isEmpty(data.text)) {
    errors.text = 'Text field is required'
  }

  return {
    errors,
    isValid: Object.keys(errors).length === 0
  }
}
github grasshopper-cms / grasshopper-core-nodejs / lib / utils / contentValidators.js View on Github external
function isAlphaNumeric(str, options){
        var isValid = validator.isAlphanumeric(str);
        if(isValid && !_.isUndefined(options)){
            isValid =  validator.isLength(str, options.min, options.max);
        }
        return isValid;
    }
github kavya-kumar94 / cravings / validation / register.js View on Github external
if (!Validator.isLength(data.username, { min: 5, max: 10 })) {
        errors.username = "Username must be between 5 and 10 characters.";
    }
    if (Validator.isEmpty(data.username)) {
        errors.username = "Username field is required.";
    }

    if (Validator.isEmpty(data.age)) {
        errors.age = "Age field is required.";
    }
    if (!Validator.isNumeric(data.age)) {
        errors.age = "Age must be a number between 12 and 100.";
    }

    if (!Validator.isLength(data.password, { min: 5, max: 10 })) {
        errors.password = "Password must be between 5 and 10 characters.";
    }
    if (Validator.isEmpty(data.password)) {
        errors.password = "Password field is required.";
    }

    if(!Validator.equals(data.password, data.password2)) {
        errors.password2 = "Password fields must match.";
    }

    return {
        errors,
        isValid: Object.keys(errors).length === 0
    }

}
github ChunML / AnnoMachine / services / frontend / src / components / RegisterLoginForm.js View on Github external
validateForm() {
    const { username, password } = this.state;

    formRules[0].valid = !!validator.isLength(username, { min: 5 });
    formRules[1].valid = !!validator.isHalfWidth(username);
    formRules[2].valid = !!validator.isLength(password, { min: 8 });

    this.setState({
      valid: formRules.reduce((res, cur) => ({ valid: res.valid && cur.valid }))
        .valid,
    });
  }