i.js
i.js
动态更新
<script type="text/javascript"> function isCardNo(idCard) { // 15位和18位身份证号码的正则表达式 var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/; // 如果通过该验证,说明身份证格式正确,但准确性还需计算 if (regIdCard.test(idCard)) { if (idCard.length == 18) { var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // 将前17位加权因子保存在数组里 var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); // 这是除以11后,可能产生的11位余数、验证码,也保存成数组 var idCardWiSum = 0; // 用来保存前17位各自乖以加权因子后的总和 for (var i = 0; i < 17; i++) { idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i]; } var idCardMod = idCardWiSum % 11;// 计算出校验码所在数组的位置 var idCardLast = idCard.substring(17);// 得到最后一位身份证号码 // 如果等于2,则说明校验码是10,身份证号码最后一位应该是X if (idCardMod == 2) { if (idCardLast == "X" || idCardLast == "x") { return true; } else { return false; } } else { // 用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码 if (idCardLast == idCardY[idCardMod]) { return true; } else { return false; } } } } else { return false; } } function IsNumber(string, info) { var number; if (string == null) { alert(info + "只能输入数字"); return false; } number = new Number(string); if (isNaN(number)) { alert(info + "只能输入数字"); return false; } else { return true; } } function checkEmail(email) { var reEmail = /^([A-Za-z0-9])(\w)+@(\w)+(\.)(com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)/; if (!email.match(reEmail) && email != "") { alert('Email格式不对!'); return true; } else { return false; } } //----------------------------------------------------空格判断 function isWhitespace(s) { var whitespace = " \t\n\r"; var i; for (i = 0; i < s.length; i++) { var c = s.charAt(i); if (whitespace.indexOf(c) >= 0) { return true; } } return false; } //--------------------------------------------------检验字符(限制不能输入的字符) function ischar(s) { var errorChar; var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; if (s == "") { alert("请您输入内容!") return false; } if (isWhitespace(s)) { alert("输入的字符中不能包含空格符,请重新输入!"); return false; } return true; } //日期 function redate(s) { s = s.split("-"); s = s[0].replace("\-", "") + s[1].replace("\-", "") + s[2].replace("\-", ""); return s; } function jtrim(s) { var i, b = 0, e = s.length; for (i = 0; i < s.length; i++) if (s.charAt(i) != ' ') { b = i; break; } if (i == s.length) return ""; for (i = s.length - 1; i > b; i--) if (s.charAt(i) != ' ') { e = i; break; } return s.substring(b, e + 1); } function CheckChinese(val){ var reg = new RegExp("[\\u4E00-\\u9FFF]+","g"); if(reg.test(val)){ alert("不能输入汉字!"); return false; } return true; } function selectEmptyClientId(x) { var selectEmpty = document.getElementById(x).value; var selectid = "#"+x; if(selectEmpty != null && selectEmpty != "" && selectEmpty != "undefined"){ $(selectid).html("<option selected='selected' value=''>请选择</option>"); }else{ $(selectid).html("<option selected='selected' value=''>请选择</option>"); $(selectid).select2().val(''); } } function telPhoneOnBlur() { var telPhonevar = $("#telPhone").val(); if (telPhonevar.length == 0) { alert("手机号码不能为空,请重新输入!"); return false; }else if (11 != telPhonevar.length) { alert("手机号码必须为11位,请重新输入!"); document.getElementById("telPhone").value = ""; return false; } if(!(/^1[34578]\d{9}$/.test(telPhonevar))){ alert("手机号码有误,请重填"); document.getElementById("telPhone").value = ""; return false; } } function lessThanTwo(checkValue, checkId){ var values = checkValue.split("."); if(values[0].length > 9){ showTip("整数部分最多只允许九位数字",'',2000,0); if(values.length == 1){ $("#" + checkId).val(values[0].substr(0, 9)); }else{ $("#" + checkId).val(values[0].substr(0, 9) + "." + values[1]); } return; } if(values.length == 2){ if(values[0] == ""){ $("#" + checkId).val("0" + checkValue); } if(values[1].length > 2){ showTip("最多只可保留两位有效数字",'',2000,0); $("#" + checkId).val(checkValue.substring(0, checkValue.length - 1)); } } } /*js将yyyymmddhhmmss字符date计算相差天数*/ function getDifDays( s1,s2 ){ var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/; var ms = "" var formatedS1 = s1.replace(pattern, '$1-$2-$3 $4:$5:$6'); var formatedS2 = s2.replace(pattern, '$1-$2-$3 $4:$5:$6'); s1 = new Date(formatedS1.replace(/-/g, '/')); s2 = new Date(formatedS2.replace(/-/g, '/')); ms = Math.abs(s1.getTime() - s2.getTime()); return ms / 1000 / 60 / 60/24; } function getDifDays( s1,s2 ){ var pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/; var ms = "" s1 = new Date(s1.replace(pattern, '$1/$2/$3 $4:$5:$6')); s2 = new Date(s2.replace(pattern, '$1/$2/$3 $4:$5:$6')); ms = Math.abs(s1.getTime() - s2.getTime()); return ms / 1000 / 60 / 60/24; } /*获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”*/ function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; } //判断当前选择时间是否小于是当前实际时间 function contrastTime(start) { var evalue = document.getElementById(start).value; var dB = new Date(evalue.replace(/-/g, "/"));//获取当前选择日期 var d = new Date(); var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();//获取当前实际日期 if (Date.parse(str) > Date.parse(dB)) {//时间戳对比 return 1; } return 0; } onkeyup="lessThanTwo(this.value, this.id);" onkeyup="this.value=this.value.replace(/\D/g\.,'')" 只能输入数字和. onkeyup="this.value=this.value.replace(/\D/g,'')" 只能输入数字 onkeyup="value=value.replace(/[^\w\.\/]/ig,'')" 只能输入英文字母和数字,不能输入中文 onkeyup="value=value.replace(/[^\w\/]/ig,'')" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')" 只能输入英文 onKeyPress="if((event.keyCode<48) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false" 只能输入数字且最多两位小数 </script>