jQuery.validator.addMethod("isPhone", function(value, element) {
var length = value.length;
return this.optional(element) || ((length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value))|| (/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(value)));
}, "请输入正确的手机号码或座机号");
jQuery.validator.addMethod("stringCheck", function(value, element) {
return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);
}, "只能包括中文字、英文字母、数字和下划线");
jQuery.validator.addMethod("isIdCardNo", function(value, element) {
return this.optional(element) || isIdCardNo(value);
}, "输入的身份证号有误");
jQuery.validator.addMethod("isChinese", function(value, element) {
return this.optional(element) || /^[\u0391-\uFFE5a-zA-Z]+$/.test(value);
}, "只能包含中文字符、英文字母");
jQuery.validator.addMethod("isEmail", function(value, element) {
return this.optional(element) || /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/.test(value);
}, "输入的电子邮箱有误");
jQuery.validator.addMethod("isBigCase", function(value, element) {
return this.optional(element) || /^[A-Z0-9]+$/.test(value);
}, "身份证号只能由数字和大写字母构成"); jQuery.validator.addMethod("isLegalName", function(value, element) {
return this.optional(element) || isLegalName(value);
}, "输入的姓名无效");
function isIdCardNo(num) {
var factorArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
var parityBit = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
var varArray = new Array();
var intValue;
var lngProduct = 0;
var intCheckDigit;
var intStrLen = num.length;
var idNumber = num;
// initialize
if ((intStrLen != 15) && (intStrLen != 18)) {
return false;
}
// check and set value
for (i = 0; i < intStrLen; i++) {
varArray[i] = idNumber.charAt(i);
if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {
return false;
} else if (i < 17) {
varArray[i] = varArray[i] * factorArr[i];
}
}
if (intStrLen == 18) {
//check date
var date8 = idNumber.substring(6, 14);
if (isDate8(date8) == false) {
return false;
}
// calculate the sum of the products
for (i = 0; i < 17; i++) {
lngProduct = lngProduct + varArray[i];
}
// calculate the check digit
intCheckDigit = parityBit[lngProduct % 11];
// check last digit
if (varArray[17] != intCheckDigit) {
return false;
}
}
else { //length is 15
//check date
var date6 = idNumber.substring(6, 12);
if (isDate6(date6) == false) {
return false;
}
}
return true;
}
function isDate6(sDate) {
if (!/^[0-9]{6}$/.test(sDate)) {
return false;
}
var year, month, day;
year = sDate.substring(0, 4);
month = sDate.substring(4, 6);
if (year < 1700 || year > 2500) return false
if (month < 1 || month > 12) return false
return true
}
function isDate8(sDate) {
if (!/^[0-9]{8}$/.test(sDate)) {
return false;
}
var year, month, day;
year = sDate.substring(0, 4);
month = sDate.substring(4, 6);
day = sDate.substring(6, 8);
var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if (year < 1700 || year > 2500) return false
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1] = 29;
if (month < 1 || month > 12) return false
if (day < 1 || day > iaMonthDays[month - 1]) return false
return true
}
var validateOptions = {
rules : {
"name" : {
required : true,
maxlength:10,
isChinese: true
},
"birthDate":{
required : true
},
"parentPhone1" : {
required : true,
isPhone : true
},
"parentPhone2" : {
isPhone : true
},
"identityCard" : {
required:true,
isBigCase:true,
isIdCardNo:true,
remote:{
url: "${path}/bd/student/idCardValidate",
type: "POST",
dataType: 'json',
data: {
identityCard: function() {
return $("#identityCard").val();
},
id: function() {
return $("#studentId").val();
}
}
}
},
/* "email" : {
required: true,
email: true,
isEmail: true
}, */
"password": {
required: true,
maxlength:25,
minlength: 5,
stringCheck: true
},
"confirm_password": {
required: true,
minlength: 5,
equalTo: "#password"
}
},
messages:{
"parentPhone1":{
required:"请至少填写一位家长联系方式"
},
"birthDate":{
required:"必须填写学生的出生日期"
},
"confirm_password":{
equalTo:"两次输入的密码不正确"
},
"identityCard":{
remote :"该用户已经注册过"
},
"password":{
minlength: "密码至少是5个字符串组成"
}
}
}
$validate.init("${pageId}theForm", validateOptions);