How to use the validator.matches 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 timeoff-management / application / lib / route / validator / leave_request.js View on Github external
if (! date_str ) throw new Error("date needs to be defined");

        date_str = req.user.company.normalise_date(date_str);

        // Ensure that normalisation went OK
        if (! validator.isDate(date_str)) throw new Error("Invalid date format");

      } catch (e) {
        console.log('Got an error ' + e);
        req.session.flash_error(label + ' should be a date');
      }
    }

    date_validator(from_date, 'From date');

    if (  !validator.matches(from_date_part, /^[123]$/)
       || !validator.matches(to_date_part, /^[123]$/)
     ){
        req.session.flash_error('Incorrect day part');
    }

    date_validator(to_date, 'To date');

    // Check if it makes sence to continue validation (as following code relies on
    // to and from dates to be valid ones)
    if ( req.session.flash_has_errors() ) {
      throw new Error( 'Got validation errors' );
    }

    // Convert dates inot format used internally
    from_date = req.user.company.normalise_date(from_date);
    to_date = req.user.company.normalise_date(to_date);
github neuroanatomy / BrainBox / controller / project / project.controller.js View on Github external
}
    
        // check that collaborator's access values are valid
        flag=true;
        for(i=0;i Access values ok");
    
        // check that the list of annotations contains at least 1 volume-type entry
        flag = false;
        for(i=0;i
github sparkswap / broker / broker-cli / utils / validations.js View on Github external
function isBlockOrderId (str) {
  if (matches(str, /^[a-zA-Z0-9_-]+$/)) {
    return str
  }

  throw new ValidationError('Block order IDs only contain upper and lower case letters, numbers, dashes (-) and underscores (_).')
}
github chadly / ghost / core / server / data / validation / index.js View on Github external
validator.extend('isSlug', function isSlug(str) {
    return validator.matches(str, /^[a-z0-9\-_]+$/);
});
github silverstripe / silverstripe-framework / admin / client / src / lib / Validator.js View on Github external
return validator.equals(value, otherValue);
      }
      case 'numeric': {
        return validator.isNumeric(value);
      }
      case 'date': {
        return validator.isDate(value);
      }
      case 'alphanumeric': {
        return validator.isAlphanumeric(value);
      }
      case 'alpha': {
        return validator.isAlpha(value);
      }
      case 'regex': {
        return validator.matches(value, config.pattern);
      }
      case 'max': {
        return value.length <= config.length;
      }
      default: {
        throw new Error(`Unknown validation rule used: '${rule}'`);
      }
    }
  }
github UdacityFrontEndScholarship / jeevan-rakht / routes / auth / signup.js View on Github external
firstname: req.body.firstname,
            lastname: req.body.lastname,
            email: req.body.email
        }
    } else {
        var inputValue = {
            nonIndiv: 'true',
            orgname: req.body.orgname,
            license: req.body.license,
            email: req.body.email,
            stock: req.body.stock
        }
    }
    partials = req.app.get('partials');
    const email = validator.isEmail(req.body.email);
    const password = validator.matches(req.body.pwd, passExpression);
    var count = 0;
    if (req.body.usertype === 'Individual') {
        var userObj = {
            user_type: req.body.usertype,
            email: req.body.email,
            password: req.body.pwd,
            indiv: {
                name: req.body.firstname + ' ' + req.body.lastname
            },
            notification_flag: 'N',
            active_flag: 'N'
        }
        if (req.body.firstname.length < 3) {
            return res.render('auth/signup', { title: 'Signup', alertMessage: 'first name must contain minimum 3 chars.', inputValue: inputValue });
        } else if (req.body.lastname.length < 3) {
            return res.render('auth/signup', { title: 'Signup', alertMessage: 'last name must contain minimum 3 chars.', inputValue: inputValue });
github amazeeio / lagoon / services / api / src / resources / project / resolvers.js View on Github external
const addProject = async (
  root,
  { input },
  {
    hasPermission,
    sqlClient,
    models,
  },
) => {
  await hasPermission('project', 'add');

  if (validator.matches(input.name, /[^0-9a-z-]/)) {
    throw new Error(
      'Only lowercase characters, numbers and dashes allowed for name!',
    );
  }
  if (!isValidGitUrl(input.gitUrl)) {
    throw new Error('The provided gitUrl is invalid.',);
  }

  let keyPair = {};
  try {
    const privateKey = R.cond([
      [R.isNil, generatePrivateKey],
      [R.isEmpty, generatePrivateKey],
      [R.T, sshpk.parsePrivateKey],
    ])(R.prop('privateKey', input));
github michaelliao / mysql-warp / utils.js View on Github external
function parseColumnDefinition(options) {
    var
        name = options.name,
        type = options.type.toLowerCase(),
        primaryKey = options.primaryKey ? true : false,
        autoIncrement = primaryKey && (options.autoIncrement ? true : false),
        allowNull = options.allowNull ? true : false,
        index = options.index ? true : false,
        unique = options.unique ? true : false,
        defaultValue = options.defaultValue,
        validate = options.validate,
        defaultValueIsFunction = typeof defaultValue === 'function';
    if (!name || !validator.matches(name, /^[a-zA-Z0-9\_]+$/)) {
        throw new Error('name is invalid: ' + name);
    }
    return {
        name: name,
        type: type,
        booleanType: type === 'bool' || type === 'boolean',
        primaryKey: primaryKey,
        autoIncrement: autoIncrement,
        allowNull: allowNull,
        index: index,
        unique: unique,
        defaultValue: defaultValue,
        validate: validate,
        defaultValueIsFunction: defaultValueIsFunction
    };
}
github iverenshaguy / book-a-meal / server / src / validations / authValidation.js View on Github external
.custom((value, { req }) => {
        if (req.body.role && req.body.role === 'caterer') {
          if (!req.body.businessName) throw new Error('Business name must be specified');
          if (value.length > 60) throw new Error('Business name must not be more than 60 characters');
          if (!validator.matches(value, /^[a-z0-9 (),.'-\s]+$/i)) {
            throw new Error('Business name can only contain letters, spaces, and the characters (,.\'-)');
          }
          return notEmpty(value, 'Business name field cannot be left blank');
        }
        return true;
      }),
    check('address')
github TryGhost / Ghost / core / server / data / validation / index.js View on Github external
validator.extend('isSlug', function isSlug(str) {
    return validator.matches(str, /^[a-z0-9\-_]+$/);
});