这里给大家提供几个有用的Javascript验证脚本以下是代码片段供大家参考
function isNum(numlowhi) { if(isNaN(num)||num<low||num>hi)return false; return true;}function isValidIP(v) { nums=vsplit(); if(numslength!=)return false; for(j=;j<;j++){ if(!isNum(nums[j]))return false; } return true;} function checkIP(ObjectDescMaybeEmpty){ var strValue= Objectvalue; if(MaybeEmpty){ if(strValuelength ==){ return true; } } if(isValidIP(strValue)==false) { alert(Desc + Format Error!); Objectfocus(); return false; } return true;}function checkPort(ObjectDesclowestMaybeEmpty){ var pattern=/^\d{}$/; var strValue= Objectvalue; if(MaybeEmpty){ if(strValuelength ==){ return true; } } if(strValuematch(pattern) == null) { alert(Desc + Format Error!); Objectfocus(); return false; } if (strValue<lowest || strValue >) { alert(Desc + Format Error!); Objectfocus(); return false; } return true;}function checkFitLongStr(ObjectDescMaybeEmpty){ var pattern=/^\S{}$/; var strValue= Objectvalue; if(MaybeEmpty){ if(strValuelength ==){ return true; } } if(strValuematch(pattern) == null) { alert(Desc + Format Error!); Objectfocus(); return false; } return true;}function checkFitLongNum(ObjectDescMaybeEmpty){ var pattern=/^\d{}$/; var strValue= Objectvalue; if(MaybeEmpty){ if(strValuelength ==){ return true; } } if(strValuematch(pattern) == null) { alert(Desc + Format Error!); Objectfocus(); return false; } return true;}function checkGC(ObjectDesc){ var pattern = /^\{}\d{}$/ var strValue = Objectvalue; if (strValuelength ==){ return true; } if(strValuematch(pattern) == null) { alert(Desc + Format Error!); Objectfocus(); return false; } if (strValue < ||strValue > ) { alert(Desc + Format Error!); Objectfocus(); return false; } return true;}