// 邮政编码验证
jQuery.validator.addMethod(“isZipCode”, function(value, element) {
var tel = /^[0-9]{6}$/;
return this.optional(element) || (tel.test(value));
}, “请正确填写您的邮政编码”);
radio和checkbox、select的验证
radio的required表示必须选中一个
<input type=”radio” id=”gender_male” value=”m” name=”gender” class=”{required:true}” />
<input type=”radio” id=”gender_female” value=”f” name=”gender”/>
checkbox的required表示必须选中
<input type=”checkbox” class=”checkbox” id=”agree” name=”agree” class=”{required:true}” />
checkbox的minlength表示必须选中的最小个数,maxlength表示最大的选中个数,rangelength:[2,3]表示选中个数区间
<input type=”checkbox” class=”checkbox” id=”spam_email” value=”email” name=”spam[]” class=”{required:true, minlength:2}” />
<input type=”checkbox” class=”checkbox” id=”spam_phone” value=”phone” name=”spam[]” />
<input type=”checkbox” class=”checkbox” id=”spam_mail” value=”mail” name=”spam[]” />
select的required表示选中的value不能为空
<select id=”jungle” name=”jungle” title=”Please select something!” class=”{required:true}”>
<option value=””></option>
<option value=”1″>Buga</option>
<option value=”2″>Baga</option>
<option value=”3″>Oi</option>
</select>
select的minlength表示选中的最小个数(可多选的select),maxlength表示最大的选中个数,rangelength:[2,3]表示选中个数区间
<select id=”fruit” name=”fruit” title=”Please select at least two fruits” class=”{required:true, minlength:2}” multiple=”multiple”>
<option value=”b”>Banana</option>
<option value=”a”>Apple</option>
<option value=”p”>Peach</option>
<option value=”t”>Turtle</option>
</select>
文章排版有点乱,仅仅是自己的记录~~










