查看: 6324|回复: 0
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
1#
发表于 2007-10-6 10:59:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
这里给大家提供几个有用的Javascript验证脚本,以下是代码片段,供大家参考。
  1. function isNum(num,low,hi) {
  2.   if(isNaN(num)||numhi)return false;
  3.   return true;
  4. }

  5. function isValidIP(v) {
  6.   nums=v.split(".");
  7.   if(nums.length!=4)return false;
  8.   for(j=0;j<4;j++){
  9.     if(!isNum(nums[j],0,255))return false;
  10.   }
  11.   return true;
  12. }

  13. function checkIP(Object,Desc,MaybeEmpty)
  14. {
  15.   var strValue= Object.value;
  16.   
  17.   if(MaybeEmpty){
  18.      if(strValue.length ==0){
  19.         return true;
  20.       }
  21.   }
  22.   
  23.   if(isValidIP(strValue)==false)
  24.   {
  25.     alert(Desc + " Format Error!");
  26.     Object.focus();
  27.     return false;
  28.   }
  29.   return true;
  30. }

  31. function checkPort(Object,Desc,lowest,MaybeEmpty)
  32. {

  33.   var pattern=/^\d{4,5}$/;
  34.   var strValue= Object.value;
  35.   
  36.   
  37.   if(MaybeEmpty){
  38.     if(strValue.length ==0){
  39.         return true;
  40.       }
  41.   }
  42.   
  43.   if(strValue.match(pattern) == null)
  44.   {
  45.     alert(Desc + " Format Error!");
  46.     Object.focus();
  47.     return false;
  48.   }
  49.   
  50.   if (strValue65535)
  51.   {
  52.       alert(Desc + " Format Error!");
  53.       Object.focus();
  54.       return false;
  55.   }
  56.   
  57.   return true;
  58. }


  59. function checkFitLongStr(Object,Desc,MaybeEmpty)
  60. {

  61.   var pattern=/^\S{0,25}$/;
  62.   var strValue= Object.value;
  63.   
  64.   if(MaybeEmpty){
  65.      if(strValue.length ==0){
  66.         return true;
  67.       }
  68.   }
  69.   if(strValue.match(pattern) == null)
  70.   {
  71.     alert(Desc + " Format Error!");
  72.     Object.focus();
  73.     return false;
  74.   }
  75.   
  76.   return true;
  77. }

  78. function checkFitLongNum(Object,Desc,MaybeEmpty)
  79. {

  80.   var pattern=/^\d{0,8}$/;
  81.   var strValue= Object.value;
  82.   
  83.   if(MaybeEmpty){
  84.      if(strValue.length ==0){
  85.         return true;
  86.       }
  87.   }
  88.   if(strValue.match(pattern) == null)
  89.   {
  90.     alert(Desc + " Format Error!");
  91.     Object.focus();
  92.     return false;
  93.   }
  94.   
  95.   return true;
  96. }

  97. function checkGC(Object,Desc)
  98. {
  99.   var pattern = /^\-{0,1}\d{1,2}$/
  100.   var strValue = Object.value;
  101.   if (strValue.length ==0){
  102.      return true;
  103.   }
  104.   
  105.   if(strValue.match(pattern) == null)
  106.   {
  107.     alert(Desc + " Format Error!");
  108.     Object.focus();
  109.     return false;
  110.   }
  111.   
  112.   if (strValue < -12 ||strValue > 18)
  113.   {
  114.     alert(Desc + " Format Error!");
  115.     Object.focus();
  116.     return false;
  117.   }
  118.   return true;
  119. }
复制代码

[ 本帖最后由 tznktg 于 2007-10-6 11:00 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表