cefriendID:cefriend
1999次访问,排名2万外好友9人,关注者13
cefriend的文章
原创 13 篇
翻译 0 篇
转载 1 篇
评论 2 篇
最近评论
dming4:未能加载文件或程序集“ASPnetPagerV2netfx2_0”或它的某一个依赖项。系统找不到指定的文件。
?????????????
conannb:收藏了 ths
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 2008年总结项目中常用到的JS验证脚本收藏

    新一篇: asp.net常用操作类之c# xml操作基类cs | 旧一篇: 自定义表单的三种方式实现

     

    2008年总结项目中常用到的JS验证脚本

    // ================================================================
    //
     本函数用于限制文本输入框中只能输入数字"0"到"9",".","-"
    //
     ================================================================
    function JHshNumberText()
    {
        
    if ( !(((window.event.keyCode >= 48&& (window.event.keyCode <= 57)) 
                
    || (window.event.keyCode == 13|| (window.event.keyCode == 46
                
    || (window.event.keyCode == 45)))
        
    {
            window.event.keyCode 
    = 0 ;
        }
        
        
    //<form name=frm>
        //<input type=text name=test value="" onKeypress="JHshNumberText()">
        //<input type=button name=submit value=submit>
        //</form>    
    }
     

    // ================================================================
    //
     本函数用于自动将输入文本框中的内容转换成大写字符 
    //
     ================================================================ 
    function JHshToUpperCase() 
    {
        
    if ((window.event.keyCode >= 97&& (window.event.keyCode <= 122)) 
        
    {
            window.event.keyCode 
    = window.event.keyCode - 32 ; 
        }
     
    }


    // ================================================================ 
    //
     本函数用于自动将输入文本框中的内容转换成小写字符 
    //
     ================================================================
    function JHshToLowerCase() 
    {
        
    if ((window.event.keyCode >= 65&& (window.event.keyCode <= 90)) 
        
    {
            window.event.keyCode 
    = window.event.keyCode + 32 ; 
        }
     
    }
      

    ///截除字符串前后空格
    function JHshTrim(sString)
    {
        
    var strTmp ;
        strTmp 
    = JHshRTrim(JHshLTrim(sString)) ;
        
    return strTmp ;
    }
     

    // -----------------------------------------------------------------------------------
    //
    本函数用于对sString字符串进行前空格截除
    //
     -----------------------------------------------------------------------------------
    function JHshLTrim(sString)

        
    var sStr,i,iStart,sResult = "";

        sStr 
    = sString.split("");
        iStart 
    = -1 ;
        
    for (i = 0 ; i < sStr.length ; i++)
        
    {
            
    if (sStr[i] != " "
            
    {
                iStart 
    = i;
                
    break;
            }

        }

        
    if (iStart == -1
        
    return "" ;}    //表示sString中的所有字符均是空格,则返回空串
        else 
        
    return sString.substring(iStart) ;}
    }


    // -----------------------------------------------------------------------------------
    //
    本函数用于对sString字符串进行后空格截除
    //
     -----------------------------------------------------------------------------------
    function JHshRTrim(sString)

        
    var sStr,i,iStart,sResult = "";
        sStr 
    = sString.split("");
        iStart 
    = -1 ;
        
    for (i = sStr.length-1 ; i >= 0 ; i--)
        
    {
            
    if (sStr[i] != " "
            
    {
                iStart 
    = i;
                
    break;
            }

        }
        
        
        
    if (iStart == -1
        
    return "" ;}    //表示sString中的所有字符均是空格,则返回空串
        else
        
    return sString.substring(0,iStart+1) ;}
    }



    //------------------------------------------------------------------------------------
    //
    判断字符串是否是日期格式,//标准格式:2004-3-29 12:05 其他格式都不允许
    //
    ------------------------------------------------------------------------------------
    function IsDate(DateString)
    {
        
    if( DateString == null )
            
    return false;
            
        
    var Dilimeter = '-';
        
    var tempY = '';
        
    var tempM = '';
        
    var tempD = '';
        
        
    var tempH = '';
        
    var tempMi = '';
        
    var tempS  = '';
        
        
    var tempArr1,tempArr2,tempArr3;
        
    if( DateString.length < 8 && DateString.length > 18 )
            
    return false;
        tempArr1 
    = DateString.split(" ");
        
    if( tempArr1.length != 2)
            
    return false;

        tempArr2 
    = tempArr1[0].split(Dilimeter);
        
    if( tempArr2.length != 3 )
            
    return false;
        tempY 
    = tempArr2[0];
        tempM 
    = tempArr2[1];
        tempD 
    = tempArr2[2];

        tempArr3 
    = tempArr1[1].split(':');
        
    if( tempArr2.length < 2 || tempArr2.length > 3)
        
    {
            
    return false;
        }

        tempH 
    = tempArr3[0];
        tempMi 
    = tempArr3[1];
        
    if( tempArr2.length == 3)
            tempS 
    = tempArr3[2];

        
    var tDateString;    
        
    if( tempArr3.length == 2)
        
    {
            tDateString 
    = tempY + '/' + tempM +'/' +tempD +' '+tempH+':'+tempMi;
        }

        
    else
        
    {
            tDateString 
    = tempY + '/' + tempM +'/' +tempD +' '+tempH+':'+tempMi+":"+tempS;
        }

        
    var tempDate = new Date( tDateString );
        
    if( isNaN(tempDate))
        
    {
            
    //alert("isNAN");
            return false;
        }


        
    if( tempArr3.length == 2)
        
    {
            
    //2004-3-29 12:05
            if((tempDate.getUTCFullYear().toString() == tempY) &&
                (tempDate.getMonth() 
    == parseInt(tempM)-1&&
                (tempDate.getDate() 
    == parseInt(tempD)) && 
                (tempDate.getHours() 
    == parseInt(tempH)) &&
                (tempDate.getMinutes() 
    == parseInt(tempMi)))
            
    {
                
    return true;
            }

            
    else
            
    {
                
    return false;
            }

        }

        
    else
        
    {
            
    //2004-3-29 12:05:30
            if((tempDate.getUTCFullYear().toString() == tempY) &&
                (tempDate.getMonth() 
    == parseInt(tempM)-1&&
                (tempDate.getDate() 
    == parseInt(tempD)) && 
                (tempDate.getHours() 
    == parseInt(tempH)) &&
                (tempDate.getMinutes() 
    == parseInt(tempMi)) &&
                (tempDate.getSeconds() 
    == parseInt(tempS)))
            
    {
                
    return true;
            }

            
    else
            
    {
                
    return false;
            }

        }

        
    }


    //------------------------------------------------------------------------------------
    //
    判断字符串日期的大小,//标准格式:2004-3-29 12:05
    //
                用之前判断日期的有效性
    //
     如果DateString1比DateString2时间晚,则返回true;否则false
    //
    ------------------------------------------------------------------------------------

    function DateCompare(DateString1, DateString2)
    {
        
    var i;
        
    var Dilimeter = '-';
        
        
    var tempArr1,tempArr2;
        tempArr1 
    = DateString1.split(Dilimeter);
        tempArr2 
    = DateString2.split(Dilimeter);
        
        
    var tDateString1 = "";    
        
    for(i=0; i<tempArr1.length; i++)
        
    {
            
    if( i < tempArr1.length-1)
                tDateString1 
    += tempArr1[i]+"/";
            
    else
                tDateString1 
    += tempArr1[i];                
        }

        
    var tDateString2 = "";    
        
    for(i=0; i<tempArr2.length; i++)
        
    {
            
    if( i < tempArr2.length-1)
                tDateString2 
    += tempArr2[i]+"/";
            
    else
                tDateString2 
    += tempArr2[i];        
            
        }


        
    var tempDate1 = new Date( tDateString1 );
        
    var tempDate2 = new Date( tDateString2 );
        
    if( isNaN(tempDate1) || isNaN(tempDate2))
        
    {
            
    return false;
        }


        
    //2004-3-29 12:05:30
        if( tempDate1.getUTCFullYear() < tempDate2.getUTCFullYear())
            
    return false;
        
    if( tempDate1.getUTCFullYear() > tempDate2.getUTCFullYear())
            
    return true;
        
    if( tempDate1.getMonth() < tempDate2.getMonth())
            
    return false;
        
    if( tempDate1.getMonth() > tempDate2.getMonth())
            
    return true;
        
    if( tempDate1.getDate() < tempDate2.getDate())
            
    return false;
        
    if( tempDate1.getDate() > tempDate2.getDate())
            
    return true;
        
    if( tempDate1.getHours() < tempDate2.getHours())
            
    return false;
        
    if( tempDate1.getHours() > tempDate2.getHours())
            
    return true;
        
    if( tempDate1.getMinutes() < tempDate2.getMinutes())
            
    return false;
        
    if( tempDate1.getMinutes() > tempDate2.getMinutes())
            
    return true;
        
    if( tempDate1.getSeconds() < tempDate2.getSeconds())
            
    return false;
        
    if( tempDate1.getSeconds() > tempDate2.getSeconds())
            
    return true;
        
    //如果相等则返回false
        return false;
    }
     

    发表于 @ 2008年04月03日 10:24:00|评论(loading...)|编辑

    新一篇: asp.net常用操作类之c# xml操作基类cs | 旧一篇: 自定义表单的三种方式实现

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © cefriend