首页 电脑 电脑学堂 查看内容

几个有用的javascript验证脚本

2006-5-9 00:05 483 0

摘要: 以下是代码片段: function isNum(num,low,hi) {  if(isNaN(num)||num<low||num>hi)return fal...
关键词: nbsp return strValue Object pattern false Desc true function MaybeEmpty

以下是代码片段: function isNum(num,low,hi) {  if(isNaN(num)||num<low||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<lowest || 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;}
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部