Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如果不是空字符串,则节点js orm强制验证_Node.js_Validation_Orm - Fatal编程技术网

Node.js 如果不是空字符串,则节点js orm强制验证

Node.js 如果不是空字符串,则节点js orm强制验证,node.js,validation,orm,Node.js,Validation,Orm,如果非必填字段不是空字符串,如何对其进行验证 我的模型: var Customer = db.define('Customer', { name : { type: "text", unique: true, required: true }, adress : { type: "text" }, zipcode : { type: "text" }, city : { type: "text" }, country

如果非必填字段不是空字符串,如何对其进行验证

我的模型:

var Customer = db.define('Customer', {
    name       : { type: "text", unique: true, required: true },
    adress     : { type: "text" },
    zipcode    : { type: "text" },
    city       : { type: "text" },
    country    : { type: "text" },
    siret      : { type: "text" },
    phone      : { type: "text" },
    fax        : { type: "text" },
    email      : { type: "text" },
    website    : { type: "text" },
    active     : { type: 'integer', required: true },
    createdAt  : { type: 'date', required: true, time: true }
}, {
    hooks: {
        beforeValidation: function () {
            this.createdAt = new Date();
            this.active    = 1;
        }
    },
    methods: {
        fullCity: function () {
            return this.zipcode + ' ' + this.city;
        }
    },
    validations: {
        name: [
            orm.enforce.notEmptyString("Not empty string"),
            orm.enforce.unique("Already exists")
        ],
        siret: orm.enforce.ranges.length(15, 15, "Must contain 15 characters"),
        email: orm.enforce.patterns.email("Not valid email")
    }
});
即使是空字符串(siret和email字段),也会进行验证。 我知道,如果值为null或未定义,则可以正常工作,但我希望使用空字符串对其进行反求

欢迎提出任何意见

谢谢