【问题标题】:Adding custom error messages using Jquery Validation使用 Jquery Validation 添加自定义错误消息
【发布时间】:2017-01-18 03:31:14
【问题描述】:

我正在尝试为我的字段验证添加自定义错误消息,而不是使用默认错误消息,但在尝试了许多不同的选项后它无法正常工作。下面是我的代码sn-p。请帮忙!

$('#myform').validate({ // initialize the plugin
        submitHandler: function (form) {
            console.log("Submitted!");
       },
        rules: {
            accountNumber: {
                required: true,
                minlength: 8,
                maxlength: 8,
                min: 11111111,
                digits: true

                },
            companyNumber: {
                required: true,
                digits: true

            }
        },

       messages: {
           min: 'Account number cannot be 00000000',
           max: 'Account number cannot be 00000000',
           digits: 'The account number must be a number'
       }

    });

});

【问题讨论】:

    标签: javascript jquery forms validation jquery-ui


    【解决方案1】:

    试试这个:

        $('#myform').validate({ // initialize the plugin
        submitHandler: function (form) {
            console.log("Submitted!");
       },
        rules: {
            accountNumber: {
                required: true,
                minlength: 8,
                maxlength: 8,
                min: 11111111,
                digits: true
    
                },
            companyNumber: {
                required: true,
                digits: true
    
            }
        },
    
       messages: {
       accountNumber: {
           min: 'Account number cannot be 00000000',
           max: 'Account number cannot be 00000000',
           digits: 'The account number must be a number'
       },
            companyNumber: {
            digits: 'The account number must be a number'
       }      
    });});
    

    【讨论】:

    • 完美...谢谢!!
    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2010-12-16
    • 1970-01-01
    相关资源
    最近更新 更多