当前位置 : 主页 > 网页制作 > Nodejs >

node.js – Meteor autoform simple-schema:如何自定义验证消息?

来源:互联网 收集:自由互联 发布时间:2021-06-16
我有这个架构: 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: Simple
我有这个架构:

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>

我想自定义Zip代码的错误消息.我没有“不遵守正则表达式”,而是希望:“您的邮政编码只能是数字,应该有5个字符”

我怎样才能做到这一点?

您可以覆盖模式的消息对象,如:

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

网友评论