<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    青菜貓(孫宇博客),青菜貓(孫宇博客),青菜貓(孫宇博客)http://www.javasdc.cn/
    posts - 29,  comments - 63,  trackbacks - 0

    /*

    -------------- 函數(shù)檢索 --------------
    trim函數(shù):                          trim() lTrim() rTrim()
    校驗(yàn)字符串是否為空:                  checkIsNotEmpty(str)
    校驗(yàn)字符串是否為整型:                checkIsInteger(str)
    校驗(yàn)整型最小值:                     checkIntegerMinValue(str,val)
    校驗(yàn)整型最大值:                     checkIntegerMaxValue(str,val)
    校驗(yàn)整型是否為非負(fù)數(shù):                isNotNegativeInteger(str)
    校驗(yàn)字符串是否為浮點(diǎn)型:              checkIsDouble(str)
    校驗(yàn)浮點(diǎn)型最小值:                   checkDoubleMinValue(str,val)
    校驗(yàn)浮點(diǎn)型最大值:                   checkDoubleMaxValue(str,val)
    校驗(yàn)浮點(diǎn)型是否為非負(fù)數(shù):              isNotNegativeDouble(str)
    校驗(yàn)字符串是否為日期型:              checkIsValidDate(str)
    校驗(yàn)兩個(gè)日期的先后:                 checkDateEarlier(strStart,strEnd)
    校驗(yàn)字符串是否為email型:            checkEmail(str)

    校驗(yàn)字符串是否為中文:                checkIsChinese(str)
    計(jì)算字符串的長度,一個(gè)漢字兩個(gè)字符:    realLength()
    校驗(yàn)字符串是否符合自定義正則表達(dá)式:    checkMask(str,pat)
    得到文件的后綴名:                    getFilePostfix(oFile)  
    -------------- 函數(shù)檢索 --------------
    */

    /**
    * added by LxcJie 2004.6.25
    * 去除多余空格函數(shù)
    * trim:去除兩邊空格 lTrim:去除左空格 rTrim: 去除右空格
    * 用法:
    *      var str = "   hello ";
    *      str = str.trim();
    */
    String.prototype.trim = function()
    {
         return this.replace(/(^[s]*)|([s]*$)/g, "");
    }
    String.prototype.lTrim = function()
    {
         return this.replace(/(^[s]*)/g, "");
    }
    String.prototype.rTrim = function()
    {
         return this.replace(/([s]*$)/g, "");
    }
    /********************************** Empty **************************************/
    /**
    *校驗(yàn)字符串是否為空
    *返回值:
    *如果不為空,定義校驗(yàn)通過,返回true
    *如果為空,校驗(yàn)不通過,返回false                參考提示信息:輸入域不能為空!
    */
    function checkIsNotEmpty(str)
    {
         if(str.trim() == "")
             return false;
         else
             return true;
    }//~~~
    /*--------------------------------- Empty --------------------------------------*/
    /********************************** Integer *************************************/
    /**
    *校驗(yàn)字符串是否為整型
    *返回值:
    *如果為空,定義校驗(yàn)通過,       返回true
    *如果字串全部為數(shù)字,校驗(yàn)通過,返回true
    *如果校驗(yàn)不通過,               返回false      參考提示信息:輸入域必須為數(shù)字!
    */
    function checkIsInteger(str)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(/^(-?)(d+)$/.test(str))
             return true;
         else
             return false;
    }//~~~
    /**
    *校驗(yàn)整型最小值
    *str:要校驗(yàn)的串。   val:比較的值
    *
    *返回值:
    *如果為空,定義校驗(yàn)通過,                 返回true
    *如果滿足條件,大于等于給定值,校驗(yàn)通過,返回true
    *如果小于給定值,                         返回false               參考提示信息:輸入域不能小于給定值!
    */
    function checkIntegerMinValue(str,val)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(typeof(val) != "string")
             val = val + "";
         if(checkIsInteger(str) == true)
         {
             if(parseInt(str,10)>=parseInt(val,10))
                 return true;
             else
                 return false;
         }
         else
             return false;
    }//~~~
    /**
    *校驗(yàn)整型最大值
    *str:要校驗(yàn)的串。   val:比較的值
    *
    *返回值:
    *如果為空,定義校驗(yàn)通過,                 返回true
    *如果滿足條件,小于等于給定值,校驗(yàn)通過,返回true
    *如果大于給定值,                         返回false        參考提示信息:輸入值不能大于給定值!
    */
    function checkIntegerMaxValue(str,val)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(typeof(val) != "string")
             val = val + "";
         if(checkIsInteger(str) == true)
         {
             if(parseInt(str,10)<=parseInt(val,10))
                 return true;
             else
                 return false;
         }
         else
             return false;
    }//~~~
    /**
    *校驗(yàn)整型是否為非負(fù)數(shù)
    *str:要校驗(yàn)的串。
    *
    *返回值:
    *如果為空,定義校驗(yàn)通過,返回true
    *如果非負(fù)數(shù),             返回true
    *如果是負(fù)數(shù),             返回false                參考提示信息:輸入值不能是負(fù)數(shù)!
    */
    function isNotNegativeInteger(str)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(checkIsInteger(str) == true)
         {
             if(parseInt(str,10) < 0)
                 return false;
             else
                 return true;
         }
         else
             return false;
    }//~~~
    /*--------------------------------- Integer --------------------------------------*/
    /********************************** Double ****************************************/
    /**
    *校驗(yàn)字符串是否為浮點(diǎn)型
    *返回值:
    *如果為空,定義校驗(yàn)通過,       返回true
    *如果字串為浮點(diǎn)型,校驗(yàn)通過,   返回true
    *如果校驗(yàn)不通過,               返回false      參考提示信息:輸入域不是合法的浮點(diǎn)數(shù)!
    */
    function checkIsDouble(str)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         //如果是整數(shù),則校驗(yàn)整數(shù)的有效性
         if(str.indexOf(".") == -1)
         {
             if(checkIsInteger(str) == true)
                 return true;
             else
                 return false;
         }
         else
         {
             if(/^(-?)(d+)(.{1})(d+)$/g.test(str))
                 return true;
             else
                 return false;
         }
    }//~~~
    /**
    *校驗(yàn)浮點(diǎn)型最小值
    *str:要校驗(yàn)的串。   val:比較的值
    *
    *返回值:
    *如果為空,定義校驗(yàn)通過,                 返回true
    *如果滿足條件,大于等于給定值,校驗(yàn)通過,返回true
    *如果小于給定值,                         返回false               參考提示信息:輸入域不能小于給定值!
    */
    function checkDoubleMinValue(str,val)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(typeof(val) != "string")
             val = val + "";
         if(checkIsDouble(str) == true)
         {
             if(parseFloat(str)>=parseFloat(val))
                 return true;
             else
                 return false;
         }
         else
             return false;
    }//~~~
    /**
    *校驗(yàn)浮點(diǎn)型最大值
    *str:要校驗(yàn)的串。   val:比較的值
    *
    *返回值:
    *如果為空,定義校驗(yàn)通過,                 返回true
    *如果滿足條件,小于等于給定值,校驗(yàn)通過,返回true
    *如果大于給定值,                         返回false        參考提示信息:輸入值不能大于給定值!
    */
    function checkDoubleMaxValue(str,val)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(typeof(val) != "string")
             val = val + "";
         if(checkIsDouble(str) == true)
         {
             if(parseFloat(str)<=parseFloat(val))
                 return true;
             else
                 return false;
         }
         else
             return false;
    }//~~~
    /**
    *校驗(yàn)浮點(diǎn)型是否為非負(fù)數(shù)
    *str:要校驗(yàn)的串。
    *
    *返回值:
    *如果為空,定義校驗(yàn)通過,返回true
    *如果非負(fù)數(shù),             返回true
    *如果是負(fù)數(shù),             返回false                參考提示信息:輸入值不能是負(fù)數(shù)!
    */
    function isNotNegativeDouble(str)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if(checkIsDouble(str) == true)
         {
             if(parseFloat(str) < 0)
                 return false;
             else
                 return true;
         }
         else
             return false;
    }//~~~
    /*--------------------------------- Double ---------------------------------------*/
    /********************************** date ******************************************/
    /**
    *校驗(yàn)字符串是否為日期型
    *返回值:
    *如果為空,定義校驗(yàn)通過,            返回true
    *如果字串為日期型,校驗(yàn)通過,        返回true
    *如果日期不合法,                    返回false     參考提示信息:輸入域的時(shí)間不合法!(yyyy-MM-dd)
    */
    function checkIsValidDate(str)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         var pattern = /^((d{4})|(d{2}))-(d{1,2})-(d{1,2})$/g;
         if(!pattern.test(str))
             return false;
         var arrDate = str.split("-");
         if(parseInt(arrDate[0],10) < 100)
             arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
         var date =   new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
         if(date.getYear() == arrDate[0]
            && date.getMonth() == (parseInt(arrDate[1],10) -1)+""
            && date.getDate() == arrDate[2])
             return true;
         else
             return false;
    }//~~~
    /**
    *校驗(yàn)兩個(gè)日期的先后
    *返回值:
    *如果其中有一個(gè)日期為空,校驗(yàn)通過,           返回true
    *如果起始日期早于等于終止日期,校驗(yàn)通過,    返回true
    *如果起始日期晚于終止日期,                  返回false     參考提示信息: 起始日期不能晚于結(jié)束日期。
    */
    function checkDateEarlier(strStart,strEnd)
    {
         if(checkIsValidDate(strStart) == false || checkIsValidDate(strEnd) == false)
             return false;
         //如果有一個(gè)輸入為空,則通過檢驗(yàn)
         if (( strStart == "" ) || ( strEnd == "" ))
             return true;
         var arr1 = strStart.split("-");
         var arr2 = strEnd.split("-");
         var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[2]);
         var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[2]);
         if(arr1[1].length == 1)
             arr1[1] = "0" + arr1[1];
         if(arr1[2].length == 1)
             arr1[2] = "0" + arr1[2];
         if(arr2[1].length == 1)
             arr2[1] = "0" + arr2[1];
         if(arr2[2].length == 1)
             arr2[2]="0" + arr2[2];
         var d1 = arr1[0] + arr1[1] + arr1[2];
         var d2 = arr2[0] + arr2[1] + arr2[2];
         if(parseInt(d1,10) > parseInt(d2,10))
            return false;
         else
            return true;
    }//~~~
    /*--------------------------------- date -----------------------------------------*/
    /********************************** email *****************************************/
    /**
    *校驗(yàn)字符串是否為email型
    *返回值:
    *如果為空,定義校驗(yàn)通過,            返回true
    *如果字串為email型,校驗(yàn)通過,       返回true
    *如果email不合法,                   返回false     參考提示信息:Email的格式不正確!
    */
    function checkEmail(str)
    {
         //如果為空,則通過校驗(yàn)
         if(str == "")
             return true;
         if (str.charAt(0) == "." || str.charAt(0) == "@" || str.indexOf('@', 0) == -1
             || str.indexOf('.', 0) == -1 || str.lastIndexOf("@") == str.length-1 || str.lastIndexOf(".") == str.length-1)
             return false;
         else
             return true;
    }//~~~
    /*--------------------------------- email ----------------------------------------*/
    /********************************** chinese ***************************************/
    /**
    *校驗(yàn)字符串是否為中文
    *返回值:
    *如果為空,定義校驗(yàn)通過,            返回true
    *如果字串為中文,校驗(yàn)通過,          返回true
    *如果字串為非中文,              返回false     參考提示信息:必須為中文!
    */
    function checkIsChinese(str)
    {
         //如果值為空,通過校驗(yàn)
         if (str == "")
             return true;
         var pattern = /^([u4E00-u9FA5]|[uFE30-uFFA0])*$/gi;
         if (pattern.test(str))
             return true;
         else
             return false;
    }//~~~
    /**
    * 計(jì)算字符串的長度,一個(gè)漢字兩個(gè)字符
    */
    String.prototype.realLength = function()
    {
       return this.replace(/[^x00-xff]/g,"**").length;
    }
    /*--------------------------------- chinese --------------------------------------*/
    /********************************** mask ***************************************/
    /**
    *校驗(yàn)字符串是否符合自定義正則表達(dá)式
    *str 要校驗(yàn)的字串   pat 自定義的正則表達(dá)式
    *返回值:
    *如果為空,定義校驗(yàn)通過,            返回true
    *如果字串符合,校驗(yàn)通過,            返回true
    *如果字串不符合,                    返回false     參考提示信息:必須滿足***模式
    */
    function checkMask(str,pat)
    {
         //如果值為空,通過校驗(yàn)
         if (str == "")
             return true;
         var pattern = new RegExp(pat,"gi")
         if (pattern.test(str))
             return true;
         else
             return false;
    }//~~~
    /*--------------------------------- mask --------------------------------------*/
    /********************************** file ***************************************/
    /**
    * added by LxcJie 2004.6.25
    * 得到文件的后綴名
    * oFile為file控件對象
    */
    function getFilePostfix(oFile)
    {
         if(oFile == null)
             return null;
         var pattern = /(.*).(.*)$/gi;
         if(typeof(oFile) == "object")
         {
             if(oFile.value == null || oFile.value == "")
                 return null;
             var arr = pattern.exec(oFile.value);
             return RegExp.$2;
         }
         else if(typeof(oFile) == "string")
         {
             var arr = pattern.exec(oFile);
             return RegExp.$2;
         }
         else
             return null;
    }//~~~
    /*--------------------------------- file --------------------------------------*/

    posted on 2007-11-18 00:11 青菜貓(孫宇) 閱讀(213) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    <2007年11月>
    28293031123
    45678910
    11121314151617
    18192021222324
    2526272829301
    2345678

    青菜貓(孫宇)結(jié)交天下朋友,在網(wǎng)上吸取知識..

    常用鏈接

    留言簿(16)

    隨筆分類

    隨筆檔案

    文章分類

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    青菜貓(孫宇博客),青菜貓(孫宇博客),青菜貓(孫宇博客)http://www.javasdc.cn/
    主站蜘蛛池模板: 色天使色婷婷在线影院亚洲| 国产在亚洲线视频观看| 成年女人18级毛片毛片免费| 蜜臀亚洲AV无码精品国产午夜.| 亚洲AV无码成H人在线观看| 日本高清高色视频免费| 亚洲乱亚洲乱妇无码| 国内精品久久久久久久亚洲| 国产麻豆视频免费观看| 国产精品免费大片一区二区| 亚洲不卡中文字幕| 久久亚洲国产精品123区| 97热久久免费频精品99| eeuss影院ss奇兵免费com| 91亚洲视频在线观看| 免费人成视频在线观看不卡| a级在线观看免费| 亚洲欧美综合精品成人导航| 久久青青草原亚洲AV无码麻豆| 真实乱视频国产免费观看| 日韩在线永久免费播放| 亚洲第一se情网站| 亚洲经典在线中文字幕| 亚洲日韩v无码中文字幕 | 国产成人亚洲影院在线观看| 啦啦啦中文在线观看电视剧免费版| 成人电影在线免费观看| 色噜噜的亚洲男人的天堂| 亚洲一级毛片在线观| 亚洲国产综合无码一区| 哒哒哒免费视频观看在线www | 日韩免费无码视频一区二区三区| 爱爱帝国亚洲一区二区三区| 亚洲国产精品乱码在线观看97| 亚洲日韩精品无码专区网址| 男人的天堂亚洲一区二区三区 | 美女被免费网站91色| 亚洲AV日韩AV无码污污网站| 亚洲国产精品成人综合色在线婷婷| 亚洲日本va中文字幕久久| 免费a级毛片无码av|