首页 > 精选文章 > 网页特效代码 > 正文

一些js代码

////////////////////前4行程序用于保护js代码不被下载 // ////////////////////基本正则表达式/////////////////// //非空验证 function NotNull (str) { return (str!=""); } //邮件地址验证 function checkEmail (str) { //邮件地址正则表达式 isEmail1=/^w+([.-]w+)*@w+([.-]w+)*.w+$/; //邮件地址正则表达式 isEmail2=/^.*@[^_]*$/; //验证邮件地址,返回结果 return (isEmail1.test(str)&&isEmail2.test(str)); } //身份证验证 function checkIDCard (str) { //身份证正则表达式(15位) isIDCard1=/^[1-9]d{7}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}$/; //身份证正则表达式(18位) isIDCard2=/^[1-9]d{5}[1-9]d{3}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{4}$/; //验证身份证,返回结果 return (isIDCard1.test(str)||isIDCard2.test(str)); } //IP验证 function checkIP (str) { //IP正则表达式 IP='(25[0-5]|2[0-4]\d|1\d\d|\d\d|\d)'; IPdot=IP+'\.'; isIPaddress=new RegExp('^'+IPdot+IPdot+IPdot+IP+'$'); //验证IP,返回结果 return (isIPaddress.test(str)); } //主页(网址)验证 function checkHomepage (str) { //主页正则表达式 //isHomepage=/^w+([.-]w)*$/; isHomepage=/^w+(.w+)+.w+$/; //验证主页,返回结果 return (isHomepage.test(str)); } //是否数字 function isNum (str) { //isNumber=/^([1-9]d*(.d+)?)|(d+(.d+))$/; isNumber=/^d+(.d+)?$/; //验证并返回结果 return (isNumber.test(str)); } //是否整数 function isInt (str) { isInteger=/^d+$/; //验证并返回结果 return (isInteger.test(str)); } //是否字母 function isChar (str) { isCharacter=/^[A-Za-z]+$/; //验证并返回结果 return (isCharacter.test(str)); } /////////////////////基本弹出窗口/////////////////// function checkBoolean(bv,i,w) { if(bv==false) { try{i.focus();}catch(e){} alert(w); return false; } return true } ////////////////////元素和取值判断//////////////////// // 已选择 function checkElement_selected(item,alert_str) { if(item.type=="select-one")return checkElement_NotNull(item,alert_str); if(alert_str.length==0)alert_str=item.title+"为必选项!"; rt=false; if(item.length>0) { for(i=0;i<item.length;i++){rt=rt||item[i].checked;} } else { rt=item.checked } return checkBoolean(rt,item[0],alert_str); return true; } // 不为空 function checkElement_NotNull(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_NotNull(v,a,w,g)); } function checkValue_NotNull(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=NotNull(v); return(checkBoolean(bv,i,w)); } // 合法邮箱 function checkElement_IsEmail(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsEmail(v,a,w,g)); } function checkValue_IsEmail(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=checkEmail(v); return(checkBoolean(bv,i,w)); } // 合法身份证 function checkElement_IsIDCard(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsIDCard(v,a,w,g)); } function checkValue_IsIDCard(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=checkIDCard(v); return(checkBoolean(bv,i,w)); } // 合法IP function checkElement_IsIP(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsIP(v,a,w,g)); } function checkValue_IsIP(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=checkIP(v); return(checkBoolean(bv,i,w)); } // 验证数字 function checkElement_IsNum(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsNum(v,a,w,g)); } function checkValue_IsNum(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=isNum(v); return(checkBoolean(bv,i,w)); } // 验证整数 function checkElement_IsInt(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsInt(v,a,w,g)); } function checkValue_IsInt(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=isInt(v); return(checkBoolean(bv,i,w)); } // 验证字母 function checkElement_IsChar(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsChar(v,a,w,g)); } function checkValue_IsChar(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=isChar(v); return(checkBoolean(bv,i,w)); } // 合法主页 function checkElement_IsHomepage(a,alert_str,g) { v=a.value; w=alert_str; if(alert_str.length==0)w=a.title+"不能为空!"; return(checkValue_IsHomepage(v,a,w,g)); } function checkValue_IsHomepage(v,i,w,g) { if(g!="NOT_TRIM")v=v.replace(/(^s*)|(s*$)/g, ""); bv=checkHomepage(v); return(checkBoolean(bv,i,w)); }
  • 上一篇:整理了一下主流 Blog 程序
  • 下一篇:特定搜索受到重视 分类搜索将执市场牛耳
  • 了解这些字:一的意思 些的意思 代的意思 码的意思