当前位置:首页 > 技术与方案 > 网络管理相关

提供几个有用的Javascript验证脚本

(2012-09-08 14:27:45)

这里给大家提供几个有用的Javascript验证脚本,以下是代码片段,供大家参考。

 

 

function isNum(num,low,hi) { if(isNaN(num)||num hi)return false; return true;}function isValidIP(v) { nums=v.split("."); if(nums.length!=4)return false; for(j=0;j 4;j++){ if(!isNum(nums[j],0,255))return false; } return true;} function checkIP(Object,Desc,MaybeEmpty){ var strValue= Object.value; if(MaybeEmpty){ if(strValue.length ==0){ return true; } } if(isValidIP(strValue)==false) { alert(Desc + " Format Error!"); Object.focus(); return false; } return true;}function checkPort(Object,Desc,lowest,MaybeEmpty){ var pattern=/^d{4,5}$/; var strValue= Object.value; if(MaybeEmpty){ if(strValue.length ==0){ return true; } } if(strValue.match(pattern) == null) { alert(Desc + " Format Error!"); Object.focus(); return false; } if (strValue 65535) { alert(Desc + " Format Error!"); Object.focus(); return false; } return true;}function checkFitLongStr(Object,Desc,MaybeEmpty){ var pattern=/^S{0,25}$/; var strValue= Object.value; if(MaybeEmpty){ if(strValue.length ==0){ return true; } } if(strValue.match(pattern) == null) { alert(Desc + " Format Error!"); Object.focus(); return false; } return true;}function checkFitLongNum(Object,Desc,MaybeEmpty){ var pattern=/^d{0,8}$/; var strValue= Object.value; if(MaybeEmpty){ if(strValue.length ==0){ return true; } } if(strValue.match(pattern) == null) { alert(Desc + " Format Error!"); Object.focus(); return false; } return true;}function checkGC(Object,Desc){ var pattern = /^-{0,1}d{1,2}$/ var strValue = Object.value; if (strValue.length ==0){ return true; } if(strValue.match(pattern) == null) { alert(Desc + " Format Error!"); Object.focus(); return false; } if (strValue -12 ||strValue 18) { alert(Desc + " Format Error!"); Object.focus(); return false; } return true;}
 

 

更多
关闭窗口 打印 
网站首页    -    联系我们    -   收藏本站    -    网站地图                                                               客户服务热线:0571-85023000
本网站所有网页信息已申请知识产权和著作权保护,版权归四海光纤公司所有,未经授权禁止任何人复制或镜像,违者必究。
公司主营:杭州光纤光缆视频会议系统,是专业的通信网络工程、视频会议系统建设专家

中华人民共和国备案号:浙ICP备10018243号