3

我有这个架构:

Users = new Meteor.Collection('users', {
    schema: {
        firstname: {
            type: String,
            label: "First name",
            max:50
        },
        lastname: {
            type: String,
            label: "Last name",
            max:50
        },
        email: {
            type: String,
            label: "E-mail",
            regEx: SimpleSchema.RegEx.Email,
            optional: false,
            max:50
        },
        tel: {
            type: String,
            label: "Phone",
            optional: false,
            max:50
        },
        zip: {
            type: String,
            label: "Zip code",
            optional: false,
            regEx: /^[0-9]{5}$/,
            max:50
        },
        city: {
            type: String,
            label: "City",
            optional: false,
            max:50
        },
    }
});

在我的模板中,我像这样使用 Autoform:

<template name="userSubmit">
    {{> quickForm collection="Users" id="insertUserForm" type="insert" validation="blur"}}
</template>

我想自定义邮政编码的错误消息。而不是“不符合正则表达式”,我想有:“你的邮政编码只能是数字,应该有 5 个字符”

我怎样才能做到这一点?

4

2 回答 2

6

您可以覆盖架构的消息对象,例如:

mySimpleSchemaInstance.messages({
  "regex": "Your Zip Code can only be numeric and should have 5 characters"
})

查看更多: https ://github.com/aldeed/meteor-simple-schema#customizing-validation-messages

于 2014-05-31T15:43:50.150 回答
0

作者找到的解决方案:

Users.simpleSchema().messages({
    "regEx zip": "Your Zip Code can only be numeric and should have 5 characters!",
});
于 2015-07-20T01:46:45.757 回答