Thank you so much!
I could make it!
In the example site, the name attribute and ID are strings that start with an uppercase letter and a lowercase letter, respectively, and that worked well, but to make it work, you need to completely set the name attribute to a string that starts with an uppercase letter, and also set the rules and message to a string that starts with a lowercase letter. I see that it works well.
I learned a lot.
I am very glad that Michael taught me how to do this.
Thank you very much!
Here’s the code that worked.
<script src="https://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.min.js"></script>
<script>
var $form = $("form");
$.validator.addMethod("pattern", function(value, element) {
return this.optional(element) || value == value.match(/^[0-9]{3}-[0-9]{4}$/);
});
// バリデーションルールを設定
$form.validate({
rules: {
Contactname: {
required: true,
minlength: 3
},
Companyname: {
required: true,
minlength: 3
},
Postalcode: {
required: true,
pattern: true
},
Adress: {
required: true,
minlength: 8,
},
Phonenumber: {
required: true,
rangelength: [10, 11],
digits: true
},
Companyemail: {
required: true,
email: true
},
Inquirydetails: {
required: true
}
},
messages: {
Contactname: {
required: "名前を入力してください",
minlength: "名前は3文字以上で入力してください"
},
Companyname: {
required: "会社名を入力してください",
minlength: "会社名は5文字以上で入力してください"
},
Postalcode: {
required: "郵便番号を入力してください",
pattern: "半角数字にて例: 123-4567のようにご入力ください",
},
Adress: {
required: "住所を入力してください",
minlength: "住所は8文字以上で入力してください"
},
Phonenumber: {
required: "電話番号を入力してください",
rangelength:"電話番号に必要な桁数で入力してください",
digits: "半角で入力してください"
},
Companyemail: {
required: "有効なメールアドレスを入力してください",
email: "有効なメールアドレスを入力してください"
},
Inquirydetails: {
required: "内容をを入力してください"
}
}
});
</script>