电影下载电视剧下载音乐下载游戏下载

您的位置:绿色软件网页制作JS/Ajax → 提供几个有用的Javascript验证脚本

提供几个有用的Javascript验证脚本
出处:本站整理 作者:佚名 日期:2007-5-7 17:06:34 人气:     [ ]

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

以下是引用片段:
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;
}

本类热门文章

本类热门文章

广告联系 - 友情链接 - 本站声明 - 下载帮助 - 关于本站 - 网络学院 - 网站地图 -
商务合作: QQ:2963458 联系我 Email: 05sun@163.com 交流群 群1:1361692 群2:7710545 群3:9292130 群4:51075709

Copyright 2003-2005 Www.05sun.Com 版权所有 蜀ICP备 05031544号

本站提供的所有软件均来自互联网下载纯属学习交流之用,如侵犯您版权的请与我们联系,我们会尽快改正请在下载24小时内删除。