$(function() {
$("#registration_form").validate({
rules: {
name: {
required: true,
lettersonly:true
},
contact: {
required: true,
numbers:true,
minlength:10,
maxlength:11
}
}
messages: {
name: {
required: "<h4><span style='color:red'>Please Enter your Name</span></h4>",
lettersonly: "<h4><span style='color:red'>Numbers And Symbols Not Allowed</span></h4>"
},
contact: {
required: "<h4><span style='color:red'>Please Enter your Phone number</span></h4>",
numbers: "<h4><span style='color:red'>Character And Symbols Are Not Allowed</span></h4>",
minlength: "<h4><span style='color:red'>Your phone Number Must Be At Least 10 Characters Long</span></h4>",
maxlength: "<h4><span style='color:red'>Please Enter No More Than 11 Numbers</span></h4>"
}
}
submitHandler: function(form) {
form.submit();
}
}); });
jQuery.validator.addMethod("numbers", function(value, element) {
return this.optional(element) || /^[0-9]+$/i.test(value);
}, "numbers only please");
name は Name フィールドの ID で、contact は Phone number フィールドの ID です。