
function checkLength(val, low, high, msg) {
	var len = val.value.length;
	if (low > -1) {
		if (len < low) {
			alert("\u60a8\u8f93\u5165\u7684\u4fe1\u606f(" + msg + ")\u4e0d\u8db3\u6700\u5c0f\u957f\u5ea6!\n\u6700\u5c0f\u957f\u5ea6: " + low + "\n\u5f53\u524d\u957f\u5ea6: " + len);
			val.focus();
			throw new Error();
		}
	}
	if (high > -1) {
		if (len > high) {
			alert("\u60a8\u8f93\u5165\u7684\u4fe1\u606f(" + msg + ")\u8d85\u8fc7\u6700\u5927\u957f\u5ea6!\n\u6700\u5927\u957f\u5ea6: " + high + "\n\u5f53\u524d\u957f\u5ea6: " + len);
			val.focus();
			throw new Error();
		}
	}
}
function checkNotEmpty(val, msg) {
	if ("" == val.value) {
		alert("\u8bf7\u586b\u5199" + msg + "!");
		val.focus();
		throw new Error();
	}
}
function checkEqual(val1, val2, msg1, msg2) {
	if (val1.value != val2.value) {
		alert(msg1 + "\u548c" + msg2 + "\u4e0d\u4e00\u81f4!");
		val1.focus();
		throw new Error();
	}
}
function checkSelected(val, msg) {
	if (val.selectedIndex == 0) {
		alert("\u8bf7\u9009\u62e9" + msg + "!");
		val.focus();
		throw new Error();
	}
}
function checkChecked(ids, msg) {
	//此处许注意当checkbox只有1个的时候,传过来的不是数组,而是一个checkbox对象
	//所以ids.length取不出来数,用getCheckNum方法会有问题
	//但是如果把getCheckNum方法放到页面上则可以正常使用
	if (ids.checked) {
		return;
	}
	if (!isChecked(ids)) {
		alert("\u8bf7\u9009\u62e9" + msg + "!");
		ids[0].focus();
		throw new Error();
	}
}
function onlyNum() {
	if ("" == event.srcElement.value || event.keyCode == 9) {
		return;
	}
	event.srcElement.value = event.srcElement.value.replace(/\D/g, "");
}
function onlyNumberic() {
	if ("" == event.srcElement.value) {
		return;
	}
	if (!isNumberic(event.srcElement.value)) {
		alert("\u8f93\u5165\u7684\u6570\u5b57\u4e0d\u7b26\u5408\u683c\u5f0f!");
		//event.srcElement.focus();
		event.srcElement.select();
	}
}
function onlyDigital() {
	if ("" == event.srcElement.value) {
		return;
	}
	if (!isDigital(event.srcElement.value)) {
		alert("\u8f93\u5165\u7684\u6570\u5b57\u4e0d\u7b26\u5408\u683c\u5f0f!");
		event.srcElement.focus();
	}
}
function onlyEmail() {
	if ("" == event.srcElement.value) {
		return;
	}
	if (!isEmail(event.srcElement.value)) {
		alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u7535\u5b50\u90ae\u7bb1!");
		event.srcElement.focus();
	}
}
function onlyUrl() {
	if ("" == event.srcElement.value) {
		return;
	}
	if (!isUrl(event.srcElement.value)) {
		alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u7f51\u5740!");
		event.srcElement.focus();
	}
}
function isEmail(val) {
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return reg.test(val);
}
function isNumberic(val) {
	var reg = /^\d+(\.\d+)?$/;
	return reg.test(val);
}
function isDigital(val) {
	var reg = /^(\-|\+)?\d+(\.\d+)?$/;
	return reg.test(val);
}
function isUrl(val) {
	var reg = /^[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	return reg.test(val);
}
function isChecked(ids) {
	return getCheckedNum(ids) > 0;
}
function getCheckedNum(ids) {
	var count = 0;
	for (var j = 0; j < ids.length; j++) {
		if (ids[j].checked) {
			count++;
		}
	}
	return count;
}


