簡體   English   中英

使用Jquery驗證添加自定義錯誤消息

[英]Adding custom error messages using Jquery Validation

我正在嘗試為字段驗證添加自定義錯誤消息,而不是使用默認消息,但是嘗試了許多不同的選項后它無法正常工作。 以下是我的代碼段。 請幫忙!

$('#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'
       }

    });

});

嘗試這個:

    $('#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'
   }      
});});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM