// 去掉前后空格 function trim(id){ var value = $("#" + id).val(); if(value == "") return; var reg = /^\s*|\s*$/g; value = value.replace(reg, ""); $("#" + id).val(value); } //校验手机号 function checkMobile(v){ var re = /^[0-9]{11}$/; if (!v || re.test(v)) { return true; }else{ return false; } } // 检查身份证号码是否符合规范,包括长度,类型 function isCardNo(card) { // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/; if (reg.test(card) === false) { return false; } return true; }; // 15位转18位身份证号 function changeFivteenToEighteen(card) { if (card.length == '15') { var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); var cardTemp = 0, i; card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6); for (i = 0; i < 17; i++) { cardTemp += card.substr(i, 1) * arrInt[i]; } card += arrCh[cardTemp % 11]; return card; } return card; }; // 校验位的检测(检验身份证件的合法性) function checkParity(card) { // 15位转18位 card = changeFivteenToEighteen(card); var len = card.length; if (len == '18') { var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); var cardTemp = 0, i, valnum; for (i = 0; i < 17; i++) { cardTemp += card.substr(i, 1) * arrInt[i]; } valnum = arrCh[cardTemp % 11]; if (valnum == card.substr(17, 1)) { return true; } return false; } return false; };