How to change the content of "This field is required" in Jquery form validation plugin?
javascript, jquery, jquery-plugins, jquery-validate, localization
Solution
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: "このフィールドは必須です"
}
});
Problem
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 name@domain.com" } } }) ``` only changes specific message for specific rule and specific element. I wrote ``` messages: { required:"このフィールドは必須です" } ``` but it doesn't work.