<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript" src="${ctx}/component/validation/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx}/component/validation/additional-methods.min.js"></script>
<script type="text/javascript" src="${ctx}/component/validation/messages_cn.js"></script>
<script type="text/javascript">
jQuery.validator.addMethod("illegal", //非法字符串
     function(value, element, params) {
		for (var i=0; i<params.length; i++) {
			if (value.indexOf(params.substring(i, i+1)) >= 0) {
				return false;
			}
		}
		return true;
     },
     "含有非法字符");

//字符验证        
jQuery.validator.addMethod("inputCheck",  function (value, element)  {       
	return this.optional(element) || /^[\u4E00-\u9FA5\uf900-\ufa2d\w]+$/.test(value);    
} ,  "只能包括中文字、英文字母、数字和下划线");
//长度验证(用到它是因为一个中文字在数据库中算两个长度)   oracle具体等于几个字节数：SELECT LENGTH('中华12') FROM DUAL; select lengthb('中华12') from dual;
jQuery.validator.addMethod("inputLength", function(value,element,param) {
	var length = value.length;
	for ( var i = 0; i < value.length; i++) {
		if (value.charCodeAt(i) > 127) {
			//length++;
			length+=2;
		}
	}
	return this.optional(element) || (length >= parseInt(param[0]) && length <= parseInt(param[1]));
}, " 请确保输入的值在{0}-{1}个字节之间(一个中文字算3个字节) ");
//手机验证      
jQuery.validator.addMethod("mobileValid", function(value, element) { 
    //var tel = /^(130|131|132|133|134|135|136|137|138|139|150|153|157|158|159|180|187|188|189)\d{8}$/; 
	var tel = /^(130|131|132|133|134|135|136|137|138|139|145|147|150|151|152|153|155|156|157|158|159|180|181|182|183|185|186|187|188|189)\d{8}$/;
    //return tel.test(value) || this.optional(element); 
    return isMobile(value) || this.optional(element); 
}, "请输入正确的手机号码");
function isMobile(num) {
	var tel = /^(130|131|132|133|134|135|136|137|138|139|145|147|150|151|152|153|155|156|157|158|159|180|181|182|183|185|186|187|188|189)\d{8}$/;
	return tel.test(num);
}
//增加身份证验证
jQuery.validator.addMethod("isIdCardNo", function (value, element) {
     return this.optional(element) || isIdCardNo(value);
 }, "请正确输入您的身份证号码");
//增加正整数验证 
jQuery.validator.addMethod("positiveInteger", function(value, element) {
	   var aint=parseInt(value);	
	    return aint>0&& (aint+"")==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 (var 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
}
/**
 * 判断是否为“YYYYMMDD”式的时期
 */
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
}
/**
 * 判断是否为Email
 */
function isEmail(val){
	var emailReg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	return emailReg.test(val);
}
/**
 * 检查页面输入的值的长度是否超过数据库指定的长度
 * val:页面输入的值
 * dbLen:数据库指定的长度
 * numChar:一个中文字算几个个字节
 * return true:不超过数据库的长度   false:超过数据库的长度
 */
function checkLen(val,dbLen,numChar) {
	var len = val.length;
	for ( var i = 0; i < val.length; i++) {
		if (val.charCodeAt(i) > 127) {
			//length++;
			len+=(numChar-1);
		}
	}
	return len<=dbLen;
}
/**
 * 检查页面输入的值的长度是否超过数据库指定的长度
 * inpComponent:input组件
 * tipComponent:如果不符合条件：显示提示的地方
 * msg:提示信息
 * dbLen:数据库指定的长度
 * numChar:一个中文字算几个个字节
 */
function checkLenAndTip(inpComponent,tipComponent,msg,dbLen,numChar) {
	var val = $(inpComponent).val();
	var len = val.length;
	for ( var i = 0; i < val.length; i++) {
		if (val.charCodeAt(i) > 127) {
			len+=(numChar-1);
		}
	}
	if (len>dbLen) {
		$(tipComponent).html(msg)[0].className="error";
		//$(inpComponent).focus();
		return false;
	} else {
		return true;
	}
}
/**
 * 检查表单input的值是否也空：  空则return
 * inpComponent:input组件
 * tipComponent:如果不符合条件：显示提示的地方
 * msg:提示信息
 */
function checkBlank(inpComponent,tipComponent,msg) {
	if ($.trim(inpComponent.val()).length == 0){
		$(tipComponent).html(msg);
		//$(inpComponent).focus();
		return false;
	}else{
		return true;
	}
	//if ($.trim(inpComponent.val()).length == 0){$(tipComponent).html(msg);$(inpComponent).focus();return;}
}
/**
 * 检查是否是URL
 */
function isUrl(url) {
	var flag = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFE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url);
	return flag;
}
/**
 * 检查是否是电话号码
 */
function isPhone(phone) {
	//var flag = /^(\d{3,4}-)?\d{7,8}$/.test(phone);
	var flag = /^0\d{2,3}-[1-9]\d{5,7}$/.test(phone);
	return flag;
}
</script>
