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

ASP
深入研究Application和Session对象(2)
深入研究Application和Session对象(3)
开始 .Net的旅程(一)
开始 .Net的旅程(二)
手把手教你使用VB来创建ASP组件(1)
手把手教你使用VB来创建ASP组件(2)
手把手教你使用VB来创建ASP组件(3)
手把手教你使用VB来创建ASP组件(4)
手把手教你使用VB来创建ASP组件(5)
手把手教你使用VB来创建ASP组件(6)
手把手教你使用VB来创建ASP组件(7)
手把手教你使用Java来编写ASP组件(1)
手把手教你使用Java来编写ASP组件(2)
手把手教你使用Java来编写ASP组件(3)
手把手教你使用Java来编写ASP组件(4)
手把手教你使用Java来编写ASP组件(5)
手把手教你使用Java来编写ASP组件(6)
ASP 3.0高级编程(二十四)
ASP 3.0高级编程(二十五)
ASP 3.0高级编程(二十六)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 144 ::
收藏到网摘: 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);}
}
//判断是否为固定的位数结