//是否为电子邮件 function IsEmail(s) { var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; if (reg.test(s)) { return true; } else { return false; } } //验证电话号码,只允许数字和“-” function IsTel(s) { var reg = /[\d|-]{7,15}/; if (reg.test(s)) { return true; } else { return false; } } //判断是否是中文 function IsCh(s) { var reg = /[\u4e00-\u9fa5]/; if (reg.test(s)) { return true; } else { return false; } } function isGBK(s){ var reg = /[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/; if (reg.test(s)) { return true; } else { return false; } } //判断输入是否全角字符 function IsSBCcase(s) { var reg = /[^\uFF00-\uFFFF]/; if (reg.test(s)) { return true; } else { return false; } } //是否国内电话号码 function IsPhone(s) { var reg = /\d{3}-\d{8}|\d{4}-\d{7}/; if (reg.test(s)) { return true; } else { return false; } } //是否腾讯QQ号 function IsQQ(s) { var reg = /[1-9][0-9]{4,}/; if (reg.test(s)) { return true; } else { return false; } } //是否中国邮政编码 function IsDak(s) { var reg = /^\d{6}$/; if (reg.test(s)) { return true; } else { return false; } } //是否身份证 /* function IsIdentityCard(s) { var reg = /\d{15}|\d{18}/; if (reg.test(s)) { return true; } else { return false; } } error: "21041119840809411a" is true */ // 是否身份证 function IsIdentityCard(num) { num = (""+num).toUpperCase(); if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) return false; return true; } //含有非数字字符 返回 true function IsNumber(s) { //适于校验非负整数 var reg = /^[01233456789]{1,}$/; if (reg.test(s)) { return true; } else { return false; } } //只能输入中文 function none_ch(obj){ var value=obj.value; value=value.replace(/[\u4e00-\u9fa5]/g,''); obj.value=value; } //只能输入数字 function none_butNumber(obj){ var value=obj.value; value=value.replace(/[^\d\\.]/g,''); obj.value=value; } //清空 /*function clearValue(obj){ obj.value=='0.00'; if(obj.value=='0.00') obj.select(); }*/ //金额格式化,这个函数请不要删除,虽然已经不用了。 function throw_off(obj){ /*var value=obj.value; var oldValue = obj.value; if(value.substring(0,1)=='0'){ value=value.substring(1); } var i=value.indexOf('.'); ar = value.split('.'); if(ar.length >2 ){ if(value.substring(i,i+1)!='.') value= value.substring(0,i+3); else value= value.substring(0,i+1); } if(i!=-1){ if(i+3<value.length) value= value.substring(0,i+3) } value=value.replace(/[^\-\d\\.]/g,''); var newValue = formatNum(value); if(newValue != oldValue){ obj.value=newValue; } */ } function add_point(obj){ /* var i =obj.value.indexOf('.'); if(obj.value.substring(0,i)==''){ obj.value=0+obj.value; } var value=obj.value; if(parseFloat(value)!=0){ var i=value.indexOf('.'); if(i==-1){ obj.value=value+".00"; } if(value.substring(i+1).length<2){ obj.value=value+"0"; } if(value.substring(i)=='.'){ obj.value=value+"00"; } }else{ obj.value='0.00'; }*/ } function clearPoint(){ var nameArray = arguments; for(i=0;i<nameArray.length;i++){ var valueList = document.getElementsByName(nameArray[i]); for(j=0;j<valueList.length;j++){ var ss=valueList[j].value; valueList[j].value=ss.replace(/[\\,]/g,''); } } } //将数字转换成三位逗号分隔的样式 function formatNum(s){ var num =""; num= s; if(!/^(\+|-)?\d+(\.\d+)?$/.test(num)){ return num; } var re = new RegExp().compile("(\\d)(\\d{3})(,|\\.|$)"); num += ""; while(re.test(num)) num = num.replace(re,"$1,$2$3"); return num; } function getTextObject(name){ try{ var e=document.getElementsByName(name); if(e.length>0) return e[0]; }catch(e){ } return ''; } //获取数字 function getIndex(s){ var regExp=/\D/g; return s.replace(regExp,''); } //去得字母 function getchar(s){ var ss=""; var r; r = s.match(/[A-Za-z]/g); for(i=0;i<r.length;i++){ ss+=r[i]; } return ss; } /* 功能:将货币数字(阿拉伯数字)(小写)转化成中文(大写) 参数:Num为字符型,小数点之后保留两位,例:Arabia_to_Chinese("1234.06") 说明:1.目前本转换仅支持到 拾亿(元) 位,金额单位为元,不能为万元,最小单位为分 2.不支持负数 */ function numtochinese(Num){ for(i=Num.length-1;i>=0;i--){ Num = Num.replace(",","")//替换tomoney()中的“,” Num = Num.replace(" ","")//替换tomoney()中的空格 } Num = Num.replace("¥","")//替换掉可能出现的¥字符 if(isNaN(Num)) { //验证输入的字符是否为数字 alert("请检查小写金额是否正确"); return; } //---字符处理完毕,开始转换,转换采用前后两部分分别转换---// part = String(Num).split("."); newchar = ""; //小数点前进行转化 for(i=part[0].length-1;i>=0;i--) { if(part[0].length > 10){ alert("位数过大,无法计算");return "";}//若数量超过拾亿单位,提示 tmpnewchar = "" perchar = part[0].charAt(i); switch(perchar){ case "0": tmpnewchar="零" + tmpnewchar ;break; case "1": tmpnewchar="壹" + tmpnewchar ;break; case "2": tmpnewchar="贰" + tmpnewchar ;break; case "3": tmpnewchar="叁" + tmpnewchar ;break; case "4": tmpnewchar="肆" + tmpnewchar ;break; case "5": tmpnewchar="伍" + tmpnewchar ;break; case "6": tmpnewchar="陆" + tmpnewchar ;break; case "7": tmpnewchar="柒" + tmpnewchar ;break; case "8": tmpnewchar="捌" + tmpnewchar ;break; case "9": tmpnewchar="玖" + tmpnewchar ;break; } switch(part[0].length-i-1) { case 0: tmpnewchar = tmpnewchar +"元" ;break; case 1: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break; case 2: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break; case 3: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break; case 4: tmpnewchar= tmpnewchar +"万" ;break; case 5: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break; case 6: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break; case 7: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break; case 8: tmpnewchar= tmpnewchar +"亿" ;break; case 9: tmpnewchar= tmpnewchar +"拾" ;break; } newchar = tmpnewchar + newchar; } //小数点之后进行转化 if(Num.indexOf(".")!=-1) { if(part[1].length > 2) { alert("小数点之后只能保留两位,系统将自动截段"); part[1] = part[1].substr(0,2) } for(i=0;i<part[1].length;i++) { tmpnewchar = "" perchar = part[1].charAt(i) switch(perchar){ case "0": tmpnewchar="零" + tmpnewchar ;break; case "1": tmpnewchar="壹" + tmpnewchar ;break; case "2": tmpnewchar="贰" + tmpnewchar ;break; case "3": tmpnewchar="叁" + tmpnewchar ;break; case "4": tmpnewchar="肆" + tmpnewchar ;break; case "5": tmpnewchar="伍" + tmpnewchar ;break; case "6": tmpnewchar="陆" + tmpnewchar ;break; case "7": tmpnewchar="柒" + tmpnewchar ;break; case "8": tmpnewchar="捌" + tmpnewchar ;break; case "9": tmpnewchar="玖" + tmpnewchar ;break; } if(i==0)tmpnewchar =tmpnewchar + "角"; if(i==1)tmpnewchar = tmpnewchar + "分"; newchar = newchar + tmpnewchar; } } //替换所有无用汉字 while(newchar.search("零零") != -1) newchar = newchar.replace("零零", "零"); newchar = newchar.replace("零亿", "亿"); newchar = newchar.replace("亿万", "亿"); newchar = newchar.replace("零万", "万"); newchar = newchar.replace("零元", "元"); if (newchar.length == 5 && newchar.substr(0,1) == "元") { newchar = newchar.replace("元", ""); } newchar = newchar.replace("零角", ""); newchar = newchar.replace("零分", ""); if (newchar.length == 0) { newchar = "零元"; } if (newchar.charAt(newchar.length-1) == "元" || newchar.charAt(newchar.length-1) == "角") newchar = newchar+"整" return newchar; } //去除首尾空格 function Trim(s) { return s.replace(/(^\s+)|(\s+$)/g, ""); } //去除全部空格 function TrimAll(s) { return s.replace(/\s+/g, ""); } //去除“'” function SafeInput(s) { return Trim(s.replace(/('+)/g, "\u2019")); } //转换非法字符for Xml function SafeXML(s) { s = s.replace(/(&+)/g, "&"); s = s.replace(/(>+)/g, ">"); s = s.replace(/(<+)/g, "<"); s = s.replace(/("+)/g, """); s = s.replace(/('+)/g, "'"); return s; } //转换非法字符for Xml function SafeXMLSBCcase(s) { s = s.replace(/(>+)/g, "\uff1e"); s = s.replace(/(<+)/g, "\uff1c"); s = s.replace(/("+)/g, "\uff02"); s = s.replace(/('+)/g, "\uff07"); s = s.replace(/(&+)/g, "\uff06"); return s; } //Html Encode function HTMLEncode(s) { s = s.replace(/(\s+)/g, " "); s = s.replace(/(\n+)/g, "<br/>"); return s; } //去除“&” function SafeURL(s) { return Trim(s.replace(/(&+)/g, "")); } //去除所有不安全字符 function SafeAll(s) { return SafeXML(SafeURL(s)); } //从身份证号里面得到日期 function getBirthdayFromIdno(IDno) { var strSeparator = "/" ; var sBirthday; if (IDno.length == 15) { sBirthday = "19" + IDno.substring(6, 8); sBirthday = sBirthday + strSeparator + IDno.substring(8, 10); sBirthday = sBirthday + strSeparator + IDno.substring(10, 12); } if (IDno.length == 18) { sBirthday = IDno.substring(6, 10); sBirthday = sBirthday + strSeparator + IDno.substring(10, 12); sBirthday = sBirthday + strSeparator + IDno.substring(12, 14); } return sBirthday; } //判断日期是否合法 //参数g_dateVal格式:"1980-01-01" function IsDate(g_dateVal) { var s = g_dateVal.replace(/-/g, "/"); var newdate = new Date(s); var s = newdate.getYear(); return isNAN(s); } //判断是否位数字 function checkObjIsNumber(objtxt, izero) { var chname; if (typeof (objtxt.chname) == "undefined") { chname = "\u5bf9\u8c61"; } else { chname = Trim(objtxt.chname); if (chname == "") { chname = "\u5bf9\u8c61"; } } objtxt.value = Trim(objtxt.value); if (isNaN(parseFloat(objtxt.value))) { alert(chname + "\u4e0d\u662f\u6709\u6548\u6570\u5b57\uff01"); objtxt.focus(); return false; } objtxt.value = parseFloat(objtxt.value); if (izero > 0) { if (!(parseFloat(objtxt.value) > 0)) { alert(chname + "\u9700\u5927\u4e8e\u96f6\uff01"); objtxt.focus(); return false; } } else { if (izero >= 0) { if (!(parseFloat(objtxt.value) >= 0)) { alert(chname + "\u9700\u5927\u4e8e\u7b49\u4e8e\u96f6\uff01"); objtxt.focus(); return false; } } } return true; } //取得单选框值 function getRadioValue(objOpt) { for (var i = 0; i < objOpt.length; i++) { if (objOpt[i].checked) { return objOpt[i].value; } } } function Debug(message) { var newwin = window.open("", "Debug", "height=500, width=700,toolbar=0, menubar=0, scrollbars=1, resizable=1, location=0, status=0"); newwin.opener = null; // 防止代码对页面修改 newwin.document.write("<html><body><h1>Debug</h1><br/>"); newwin.document.write(message); newwin.document.write("<br/></body></html>"); newwin.focus(); }