How to use the validator.extend 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 ozum / sequelize-pg-generator / node_modules / sequelize / lib / instance-validator.js View on Github external
, Utils = require('./utils')
  , sequelizeError = require('./errors')
  , Promise = require('./promise')
  , DataTypes = require('./data-types')
  , _ = require('lodash');

function noop() {}

// Deprecate this.
Validator.notNull = function() {
  throw new Error('Warning "notNull" validation has been deprecated in favor of Schema based "allowNull"');
};

// https://github.com/chriso/validator.js/blob/1.5.0/lib/validators.js

Validator.extend('notEmpty', function(str) {
  return !str.match(/^[\s\t\r\n]*$/);
});

Validator.extend('len', function(str, min, max) {
  return this.isLength(str, min, max);
});

Validator.extend('isUrl', function(str) {
  return this.isURL(str);
});

Validator.extend('isIPv6', function(str) {
  return this.isIP(str, 6);
});

Validator.extend('isIPv4', function(str) {
github doramart / DoraCMS / routes / validat.js View on Github external
}else{
        res.redirect("/admin");
    }

});

//自定义校验扩展
validator.extend('isUserName', function (str) {
    return /^[a-zA-Z][a-zA-Z0-9_]{4,11}$/.test(str);
});

validator.extend('isGBKName', function (str) {
    return /[\u4e00-\u9fa5]/.test(str);
});

validator.extend('isPsd', function (str) {
    return /(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{5,}/.test(str);
});

validator.extend('isQQ', function (str) {
    return RegExp(/^[1-9][0-9]{4,9}$/).test(str);
});


//只能是英文
validator.extend('isEn', function (str) {
    return /^\S+[a-z A-Z]$/.test(str);
});


module.exports = router;
github doramart / DoraCMS / routes / validat.js View on Github external
router.get("/manage/*",function(req,res,next){

    if(isAdminLogined(req)){
        next();
    }else{
        res.redirect("/admin");
    }

});

//自定义校验扩展
validator.extend('isUserName', function (str) {
    return /^[a-zA-Z][a-zA-Z0-9_]{4,11}$/.test(str);
});

validator.extend('isGBKName', function (str) {
    return /[\u4e00-\u9fa5]/.test(str);
});

validator.extend('isPsd', function (str) {
    return /(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{5,}/.test(str);
});

validator.extend('isQQ', function (str) {
    return RegExp(/^[1-9][0-9]{4,9}$/).test(str);
});


//只能是英文
validator.extend('isEn', function (str) {
    return /^\S+[a-z A-Z]$/.test(str);
});
github EasyERP / EasyERP_open_source / helpers / validator.js View on Github external
return regExp.test(str);
});

validator.extend('isNotValidChars', function (str) {
    var regExp = /[~<>\^\*₴]/;

    return regExp.test(str);
});

validator.extend('isPass', function (str) {
    var regExp = /^[\w\.@]{3,100}$/;

    return regExp.test(str);
});

validator.extend('isProfile', function (str) {
    var regExp = /^\d+$/;

    return regExp.test(str);
});

validator.extend('isEmployeeName', function (str) {
    var regExp = /^[a-zA-Z]+[a-zA-Z-_\s]+$/;

    return regExp.test(str);
});

validator.extend('isEmployeeDate', function (str) {
    var regExp = /[a-zA-Z0-9]+[a-zA-Z0-9-,#@&*-_\s()\.\/\s]+$/;

    return regExp.test(str);
});
github ozum / sequelize-pg-generator / node_modules / sequelize / lib / instance-validator.js View on Github external
function extendModelValidations(modelInstance) {
  Validator.extend('isImmutable', function(str, param, field) {
    return (modelInstance.isNewRecord || modelInstance.dataValues[field] === modelInstance._previousDataValues[field]);
  });
}
github CleverStack / node-seed / lib / classes / Validator.js View on Github external
return isNaN(number) || number <= val;
});

validator.extend('not', function(str, pattern, modifiers) {
  return this.notRegex(str, pattern, modifiers);
});

validator.extend('contains', function(str, elem) {
  return str.indexOf(elem) >= 0 && !!elem;
});

validator.extend('notContains', function(str, elem) {
  return !this.contains(str, elem);
});

validator.extend('is', function(str, pattern, modifiers) {
  return this.regex(str, pattern, modifiers);
});

var Validator = Class.extend(
{
  setup: function() {
    utils.helpers.defineProperty(this, 'validator', { value: validator });
  },

  validate: function(Class, model) {
    if (model === undefined) {
      model = Class;
      Class = model.Class;
    }

    return new Promise(this.proxy('validateModel', Class, model));
github ozum / sequelize-pg-generator / node_modules / sequelize / lib / instance-validator.js View on Github external
return !this.isIn(str, values);
});

Validator.extend('regex', function(str, pattern, modifiers) {
  str += '';
  if (Object.prototype.toString.call(pattern).slice(8, -1) !== 'RegExp') {
    pattern = new RegExp(pattern, modifiers);
  }
  return str.match(pattern);
});

Validator.extend('notRegex', function(str, pattern, modifiers) {
  return !this.regex(str, pattern, modifiers);
});

Validator.extend('isDecimal', function(str) {
  return str !== '' && str.match(/^(?:-?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/);
});

Validator.extend('min', function(str, val) {
  var number = parseFloat(str);
  return isNaN(number) || number >= val;
});

Validator.extend('max', function(str, val) {
  var number = parseFloat(str);
  return isNaN(number) || number <= val;
});

Validator.extend('not', function(str, pattern, modifiers) {
  return this.notRegex(str, pattern, modifiers);
});
github ozum / sequelize-pg-generator / node_modules / sequelize / lib / instance-validator.js View on Github external
Validator.extend('isDecimal', function(str) {
  return str !== '' && str.match(/^(?:-?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/);
});

Validator.extend('min', function(str, val) {
  var number = parseFloat(str);
  return isNaN(number) || number >= val;
});

Validator.extend('max', function(str, val) {
  var number = parseFloat(str);
  return isNaN(number) || number <= val;
});

Validator.extend('not', function(str, pattern, modifiers) {
  return this.notRegex(str, pattern, modifiers);
});

Validator.extend('contains', function(str, elem) {
  return str.indexOf(elem) >= 0 && !!elem;
});

Validator.extend('notContains', function(str, elem) {
  return !this.contains(str, elem);
});

Validator.extend('is', function(str, pattern, modifiers) {
  return this.regex(str, pattern, modifiers);
});

function extendModelValidations(modelInstance) {
github CleverStack / node-seed / lib / classes / Validator.js View on Github external
return this.isIP(str, 4);
});

validator.extend('notIn', function(str, values) {
  return !this.isIn(str, values);
});

validator.extend('regex', function(str, pattern, modifiers) {
  str += '';
  if (Object.prototype.toString.call(pattern).slice(8, -1) !== 'RegExp') {
    pattern = new RegExp(pattern, modifiers);
  }
  return str.match(pattern);
});

validator.extend('notRegex', function(str, pattern, modifiers) {
  return !this.regex(str, pattern, modifiers);
});

validator.extend('isDecimal', function(str) {
  return str !== '' && str.match(/^(?:-?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/);
});

validator.extend('min', function(str, val) {
  var number = parseFloat(str);
  return isNaN(number) || number >= val;
});

validator.extend('max', function(str, val) {
  var number = parseFloat(str);
  return isNaN(number) || number <= val;
});
github CleverStack / node-seed / lib / classes / Validator.js View on Github external
var utils       = require('utils')
  , injector    = require('injector')
  , async       = require('async')
  , Class       = injector.getInstance('Class')
  , Promise     = require('bluebird')
  , validator   = require('validator');

validator.extend('notEmpty', function(str) {
  return !str.match(/^[\s\t\r\n]*$/);
});

validator.extend('len', function(str, min, max) {
  return this.isLength(str, min, max);
});

validator.extend('isUrl', function(str) {
  return this.isURL(str);
});

validator.extend('isIPv6', function(str) {
  return this.isIP(str, 6);
});

validator.extend('isIPv4', function(str) {
  return this.isIP(str, 4);
});

validator.extend('notIn', function(str, values) {
  return !this.isIn(str, values);
});

validator.extend('regex', function(str, pattern, modifiers) {