<br>
$(document).ready(function(){ </p>
<p>/* 设置默认属性 */<br><br>
$.validator.setDefaults({<br><br>
submitHandler: function(form) { form.submit(); }<br><br>
});<br><br>
// 中文字两个字节<br><br>
jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {<br><br>
var length = value.length;<br><br>
for(var i = 0; i < value.length; i++){<br><br>
if(value.charCodeAt(i) > 127){<br><br>
length++;<br><br>
}<br><br>
}<br><br>
return this.optional(element) || ( length >= param[0] && length <= param[1] );<br><br>
}, "请确保输入的值在3-15个字节之间(一个中文字算2个字节)"); </p>
<p>/* 追加自定义验证方法 */<br><br>
// 身份证号码验证<br><br>
jQuery.validator.addMethod("isIdCardNo", function(value, element) {<br><br>
return this.optional(element) || isIdCardNo(value);<br><br>
}, "请正确输入您的身份证号码"); </p>
<p>// 字符验证<br><br>
jQuery.validator.addMethod("userName", function(value, element) {<br><br>
alert(/^[a-zA-Z\u0391-\uFFE5]{2}[\u0391-\uFFE5\w]{0,14}$/ig.test(value)); <br>
return this.optional(element) || /^[a-zA-Z\u0391-\uFFE5]{2}[\u0391-\uFFE5\w]{0,14}$/ig.test(value);<br><br>
}, "用户名只能包括中文字、英文字母、数字和下划线"); </p>
<p>// 手机号码验证<br><br>
jQuery.validator.addMethod("isMobile", function(value, element) {<br><br>
var length = value.length;<br><br>
return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/.test(value));<br><br>
}, "请正确填写您的手机号码"); </p>
<p>// 电话号码验证<br><br>
jQuery.validator.addMethod("isPhone", function(value, element) {<br><br>
var tel = /^(\d{3,4}-?)?\d{7,9}$/g;<br><br>
return this.optional(element) || (tel.test(value));<br><br>
}, "请正确填写您的电话号码"); </p>
<p>// 邮政编码验证<br><br>
jQuery.validator.addMethod("isZipCode", function(value, element) {<br><br>
var tel = /^[0-9]{6}$/;<br><br>
return this.optional(element) || (tel.test(value));<br><br>
}, "请正确填写您的邮政编码"); </p>
<p>$("#regFrom").validate({<br><br>
/* 设置验证规则 <em>/<br><br>
rules: {<br><br>
userName: {<br><br>
required: true,<br><br>
userName: true,<br><br>
byteRangeLength: [3,15]<br><br>
},<br><br>
password: {<br><br>
required: true,<br><br>
minlength: 5<br><br>
},<br><br>
repassword: {<br><br>
required: true,<br><br>
minlength: 5,<br><br>
equalTo: "#password"<br><br>
},<br><br>
question: {<br><br>
required: true<br><br>
},<br><br>
answer: {<br><br>
required: true<br><br>
},<br><br>
realName: {<br><br>
required: true<br><br>
},<br><br>
cardNumber: {<br><br>
isIdCardNo: true<br><br>
},<br><br>
mobilePhone: {<br><br>
isMobile: true<br><br>
},<br><br>
phone: {<br><br>
isPhone: true<br><br>
},<br><br>
email: {<br><br>
required: true,<br><br>
email: true<br><br>
},<br><br>
zipCode: {<br><br>
isZipCode:true<br><br>
}<br><br>
},<br><br>
/</em> 设置错误信息 */<br><br>
messages: {<br><br>
userName: {<br><br>
required: "请填写用户名", <br>
userName:"请输入中文,英文", <br>
byteRangeLength: "用户名必须在3-15个字符之间(一个中文字算2个字符)"<br><br>
},<br><br>
password: {<br><br>
required: "请填写密码",<br><br>
minlength: jQuery.format("输入{0}.")<br><br>
},<br><br>
repassword: {<br><br>
required: "请填写确认密码",<br><br>
equalTo: "两次密码输入不相同"<br><br>
},<br><br>
question: {<br><br>
required: "请填写您的密码提示问题"<br><br>
},<br><br>
answer: {<br><br>
required: "请填写您的密码提示答案"<br><br>
},<br><br>
realName: {<br><br>
required: "请填写您的真实姓名"<br><br>
},<br><br>
email: {<br><br>
required: "请输入一个Email地址",<br><br>
email: "请输入一个有效的Email地址"<br><br>
}<br><br>
},<br><br>
}); <br>
}); </p>
<p>
userName:
password:
repassword:
question:
answer:
realName:
eamil: