我在使用 jQuery 验证时遇到问题,可以使用一些建议。
有没有一种方法可以验证此表单中的三个电话号码字段,而该组只有一条错误消息?任何帮助是极大的赞赏。
形式
<form id="mForm" name="form">
<div class="field right">
<label class="labelStd" id="phoneNumber">Phone Number*</label>
<input name="txtPhone1" type="text" maxlength="3" id="txtPhone1" class="small-phone" name="txtPhone1" Onchange="Tab(this, 'txtPhone2');" />
<input name="txtPhone2" type="text" maxlength="3" id="txtPhone2" class="small-phone" name="txtPhone2" Onchange="Tab(this, 'txtPhone3');" />
<input name="txtPhone3" type="text" maxlength="4" id="txtPhone3" class="small-phone" name="txtPhone3" />
</div>
<button type="submit" id="btn_submit" class="button-black right">SEND</button>
</form>
脚本(使用 jquery 验证)
<script type="text/javascript">
$("#mForm").validate({
onfocusout:false,
focuseInvalid:false,
onkeyup:false,
rules: {
txtPhone1:{
required: true,
digits: true,
minlength: 3,
maxlength: 3
},
txtPhone2:{
required: true,
digits: true,
minlength: 3,
maxlength: 3
},
txtPhone3:{
required: true,
digits: true,
minlength: 4,
maxlength: 4
}
},
messages: {
txtPhone1: "Your phone number is required.",
txtPhone2: "Your phone number is required.",
txtPhone3: "Your phone number is required."
}
});
$("#mForm").submit(function(){
if($(this).valid()){
form.submit();
}
else{ }
});
</script>