开发者

How to change the content of "This field is required" in Jquery form validation plugin?

How can I change the general message of "This field is required" in Jquery form validation plugin to "このフィールドは必須です"? The color of the message can be changed by using the following cod开发者_运维知识库e:

<style type="text/css">
label.error {color: red;}

</style>

But how to change the content?

I want to change all "This filed is required" messages.

I want to change all "required" messages to "このフィールドは必須です".

$(".selector").validate({
   rules: {
     name: "required",
     email: {
       required: true,
       email: true
     }
   },
   messages: {
     name: "Please specify your name",
     email: {
       required: "We need your email address to contact you",
       email: "Your email address must be in the format of name@domain.com"
     }
   }
})

only changes specific message for specific rule and specific element.

I wrote

 messages: { 
        required:"このフィールドは必須です"

        }

but it doesn't work.


I tried the accepted answer and it did not work for me at all. I did more searching on Google and found this article.

Using this line of code solved my problem:

$.validator.messages.required = "Your new required message here!";


The messages object has several interesting attributes to adjust:

messages: {
    required: "This field is required.",
    remote: "Please fix this field.",
    email: "Please enter a valid email address.",
    url: "Please enter a valid URL.",
    ...
}

See the source.

These can be set as defaults via the setDefaults() method:

$.validator.setDefaults({
    messages: {
        required: "このフィールドは必須です"
    }
});


You can use the messages option in the validate method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜