这是一段javascript代码
$("#myform").validate({
rules: {
"studentid": {
required: true
, digits: true
, maxlength: 7
, minlength: 7
}
我想要1条消息来说明必需,数字,最大长度和最小长度规则。我希望此文本显示:"格式无效"
我知道我可以为每个规则单独指定一条消息,如:
messages: {
name: {
required: "We need your email address to contact you",
minlength: jQuery.validator.format("At least {0} characters required!")
}
}
但是有可能有捷径吗?谢谢! :)
答案 0 :(得分:1)
你可以这样做:
var errorMsg = "Invalid Format";
messages: {
name: {
required: errorMsg,
minlength: errorMsg
}
}
答案 1 :(得分:1)
我希望收到
required
,digits
,maxlength
和minlength
规则的1条消息。我希望此文字显示:"Invalid format"
您可以向该字段分配一条消息,它将应用于该字段的所有规则......
$("#myform").validate({
rules: {
studentid: {
required: true,
digits: true,
maxlength: 7,
minlength: 7
}
},
messages: {
studentid: "Invalid Format" // same message for all rules on this field
}
});