当前位置: 首页 > 图文教程 > 网络编程 > ASP > 综合的判断用户输入的合法性的函数

ASP
ASP简单入门教程(2):ASP环境配置
ASP简单入门教程(3):ASP语法
ASP简单入门教程(4):ASP变量
ASP简单入门教程(5):ASP子程序
HTTP 500 - 内部服务器错误(补充内容)
ASP教程:IIS中配置多站点
ASP实例教程:Content Rotator (ASP 3.0)
ASP实例教程:Content Linking组件
ASP实例教程:Browser Capabilities组件
ASP实例教程:AdRotator组件
ASP实例教程:Dictionary对象
ASP实例教程:File对象
ASP实例教程:Drive对象
ASP实例教程:TextStream对象
关于学习ASP的20个测试题目
ASP实例教程:Server对象
ASP实例教程:Session对象
ASP实例教程:用户信息和服务器
asp教程:解决IIS安装问题
ASP网站数据库被挂木马的处理办法

ASP 中的 综合的判断用户输入的合法性的函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 81 ::
收藏到网摘: n/a

  <script language="javascript">
//限制输入字符的位数开始
//m是用户输入,n是要限制的位数
function issmall(m,n)
{
if ((m<n) && (m>0))
  {
  return(false);
  }
else
{return(true);}
}

//限制输入字符的位数结束

//判断密码是否输入一致开始
function issame(str1,str2)
{
if (str1==str2)
{return(true);}
else
{return(false);}
}
//判断密码是否输入一致结束

//判断是否为空开始
function isnotnull(str)
{
if (str.length=="")
  {
  return(false);
  }
else
{
  return(true);
}
}

//判断是否为空结束


//判断用户名是否为数字字母下滑线开始
function notchinese(str){
var reg=/[^A-Za-z0-9_]/g
    if (reg.test(str)){
    return (false);
    }else{
return(true);    }
}

//判断用户名是否为数字字母下滑线结束

//判断是否为日期型开始
function isDate (theStr) {
    var the1st = theStr.indexOf('-');
    var the2nd = theStr.lastIndexOf('-');
    
    if (the1st == the2nd) { return(false); }
    else {
        var y = theStr.substring(0,the1st);
        var m = theStr.substring(the1st+1,the2nd);
        var d = theStr.substring(the2nd+1,theStr.length);
        var maxDays = 31;
        
        if (fucCheckNUM(m)==false || fucCheckNUM(d)==false || fucCheckNUM(y)==false) {
            return(false); }
        else if (y.length < 4) { return(false); }
        else if ((m<1) || (m>12)) { return(false); }
        else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
        else if (m==2) {
            if (y % 4 > 0) maxDays = 28;
            else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
               else maxDays = 29;
        }
        if  ((m<1) || (m>maxDays)) { return(false); }
        else { return(true); }
    }
}

function fucCheckNUM(NUM)
{
    var i,j,strTemp;
    strTemp="0123456789";
    if ( NUM.length== 0)
        return 0
    for (i=0;i<NUM.length;i++)
    {
        j=strTemp.indexOf(NUM.charAt(i));    
        if (j==-1)
        {
        //说明有字符不是数字
            return 0;
        }
    }
    //说明是数字
    return 1;
}

//判断是否为日期型结束


//判断是否为固定的位数开始
function isatn(m,n)
{
if (m!=n)
  {
  return(false);
  }
else
{
return(true);}
}
//判断是否为固定的位数结