views:

169

answers:

3

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 code:

<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 [email protected]"
     }
   }
})

only changes specific message for specific rule and specific element.

I wrote

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

        }

but it doesn't work.

+3  A: 

You can use the messages option in the validate method.

kgiannakakis
+1  A: 

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: "このフィールドは必須です"
    }
});
jensgram
+1  A: 

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!";
JustinP8