熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

提供幾個有用的Javascript驗證腳本

2022-06-13   來源: JSP教程 

  這裡給大家提供幾個有用的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; }


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19702.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.